;### Line drawing part

                 processor 6502

;Memory map:
;$80-$ff Zero page

;$7000-$7fff Code

;$8000-$83ff Screen0
Screen0 = $8000
;$8000-$83ff Screen1
Screen1 = $8400
;$8800-$8fff Charset0
x1_old = $9000
y1_old = $9100
x2_old = $9200
y2_old = $9300
xa_old = $9400
xa2_old = $9500 ;-$95ff
;$a000-$a7ff Charset1
;$a800-$afff Charset2
;$b000-$b7ff Charset3
;$b800-$bfff Charset4

charset  = $8800
charset1 = $a000
charset2 = $a800
charset3 = $b000
charset4 = $b800


;Line-draw routine in a 16x16 charset image
;128pixels wide, 128 pixels high
;Could also be "extended" to sprites in the border.

;Screen:
;00 10 20
;01 11 21
;02 12
;...
;0f 1f 2f

;Pixel (00,00) has address $8800
;Pixel (00,01) has address $8801
;Pixel (00,7f) has address $887f
;Pixel (08,00) has address $8880
;Pixel (08,7f) has address $88ff
;Pixel (10,00) has address $8900

;The left sprite in the border will have x-coordinates "$68-$7f"
;The right sprite in the border will have x-coordinates 40*8 mod 128 = "$40-$57"


  include globals.s

  seg.u zp
  org $0080
zp_start:

savea: dc.b 0
savex: dc.b 0
savey: dc.b 0
nmi_savea: dc.b 0
nmi_savex: dc.b 0
nmi_savey: dc.b 0

part_finished: dc.b 0
IRQ_finished: dc.b 0

countdown: dc.b 0,0

  seg code
  org $7000

;###
;### up-scroller
;###

start_up:
;  lda #0
  sta lineversion

  lda #0
  sta add_nSub

  lda #$1a
  sta up_irq1_raster
  lda #$28-$14
  sta up_irq4_raster

  ldx #0
.coll:
  lda #$1
  sta $d800,x
  sta $d900,x
  sta $d980,x
  lda #0
  sta $da80,x
  sta $daf7,x
  inx
  bne .coll

  ldx #0
  lda #$0
.scr0:
  sta Screen0,x
  sta Screen0+$100,x
  sta Screen0+$200,x
  sta Screen0+$2f7,x

  sta charset+$000,x
  sta charset+$100,x
  sta charset+$200,x
  sta charset+$300,x
  sta charset+$400,x
  sta charset+$500,x
  sta charset+$600,x
  sta charset+$700,x

  sta charset1+$000,x
  sta charset1+$100,x
  sta charset1+$200,x
  sta charset1+$300,x
  sta charset1+$400,x
  sta charset1+$500,x
  sta charset1+$600,x
  sta charset1+$700,x

  sta charset2+$000,x
  sta charset2+$100,x
  sta charset2+$200,x
  sta charset2+$300,x
  sta charset2+$400,x
  sta charset2+$500,x
  sta charset2+$600,x
  sta charset2+$700,x

  sta charset3+$000,x
  sta charset3+$100,x
  sta charset3+$200,x
  sta charset3+$300,x
  sta charset3+$400,x
  sta charset3+$500,x
  sta charset3+$600,x
  sta charset3+$700,x
  inx
  bne .scr0
.scr1:
  sta charset4+$000,x
  sta charset4+$100,x
  sta charset4+$200,x
  sta charset4+$300,x
  sta charset4+$400,x
  sta charset4+$500,x
  sta charset4+$600,x
  sta charset4+$700,x
  inx
  bne .scr1

;Initialize screen with characters:
  lda #<Screen0
  sta scr0poi
  lda #>Screen0
  sta scr0poi+1
  ldx #0
.scr0_3:
  txa
  ldy #0
.scr0_2:
scr0poi = * + 1
  sta $8000
  inc scr0poi
  bne .nw
  inc scr0poi+1
.nw:
  clc
  adc #$10
  iny
  cpy #$28
  bne .scr0_2
  inx
;Only do the first 16 rows
  cpx #$10
  bne .scr0_3

  jsr init_frame
  jsr init_scroll

  lda lineversion
  jsr init_line
  jsr init_frame

  lda #$02
  sta countdown+1

  lda savepoi_distance
  clc
  adc #1
  sta countdown

;Wait until bottom of screen:
  lda loaderirq_cou
.wait_f:
  cmp loaderirq_cou
  beq .wait_f

  sei
  lda #$35
  sta $01
  lda #$7f
  sta $dc0d
  lda $dc0d
;  ldx #$2e
;.d000loop:
;  lda up_d000defaults,x
;  sta $d000,x
;  dex
;  cpx #$11
;  bne .d000loop
;  lda #%00000001
;  sta $dd00   ;Bank at $8000-$bfff

  lda #<up_irq3
  sta $fffe
  lda #>up_irq3
  sta $ffff
  lda #up_irq3_raster
  sta $d012
  lda #$fc   ;set nmi to rti
  sta $fffa
  lda #$ff
  sta $fffb
  lda #$40   ;rti
  sta $fffc
  lda #$01
  sta $d019
  sta $d01a
  cli

next_version:


up_ever:
  lda IRQ_finished
  beq up_ever
  lda #0
  sta IRQ_finished

  dec countdown
  bne .no_end_part
  dec countdown+1
  bne .no_end_part

up_end_part:

;Only do one line each time... so this part is skipped
;  lda lineversion
;  clc
;  adc #1
;  sta lineversion
;  cmp #lineversions
;  beq .really_exit
;  jmp next_version

.really_exit:
  sei
  lda #0
  sta $dc0e ;stop timers
  lda #$7f
  sta $dc0d
  lda $dc0d
;  jmp next_demo_part
  lda #$a0
.wait:
  cmp $d012
  bne .wait
  rts

.no_end_part:

;  lda #10
;  sta $d020
  jsr scroll_rut
  jsr frame_rut
  jsr line_erase

always_draw = * + 1
  lda #0
  cmp #1
  beq .draw

  lda countdown+1
  cmp #1
  bne .draw
  lda countdown
  sec
  sbc #1
  cmp savepoi_distance
  bcs .draw
  inc savepoi
  jmp .nodraw

.draw:
  jsr line
.nodraw:
;  lda #0
;  sta $d020
;  lda #2
;  sta $d020

  lda countdown+1
  cmp #1
  bne .no_shutdown
  lda countdown
  sec
  sbc #1
  cmp #$15
  bcs .no_shutdown
  lda #1
  sta add_nSub
.no_shutdown:


  jmp up_ever

.upper:
  ldx #6
.waitt:
  dex
  bne .waitt
  lda #$01
  sta $d020
  sta $d021
  lda #$32
.wa3
  cmp $d012
  bne .wa3
  ldx #1
.waitt2:
  dex
  bne .waitt2
  nop
  nop
  jmp .back

;up_irq1_raster = $ba
up_irq1:
  sta savea
  stx savex
  lda #$31
  cmp $d012
  bcs .upper
  lda #$73
  sta $d011

.back:
  lda #$02
  sta $dd00

  nop
  lda #$85  ;screen at $6000, spr data at $63f8
  sta $d018
  lda #$c8
  sta $d016
  lda #up_irq2_raster
  sta $d012
  lda #1
  sta $d020
  sta $d021
  ldx #$3b
  stx $d011
  sty savey
  inc IRQ_finished

  lda #$ff
  sta $d015
  lda #$00
  sta $d01b ;Spr-background priority

  ldx exitbounce
  lda sintbl,x
  clc
  adc #$80
  lsr
  lsr
  lsr
  lsr
  clc
  adc #$18
  sta $d000
  clc
  adc #$18
  sta $d002
;  lda sintbl+$35,x
;  clc
;  adc #$80
;  lsr
;  lsr
;  lsr
;  lsr
;  lsr
;  sta $d001
;  sta $d003
  inc exitbounce

  lda #<up_irq2
  sta $fffe
  lda #>up_irq2
  sta $ffff
  asl $d019
  lda savea
  ldx savex
  ldy savey
  rti

up_irq2_raster = $f9
up_irq2:
  sta savea
  stx savex
  sty savey

  lda #$ff
  sta $d015
  lda #0
  sta $3fff
  lda #up_irq3_raster
  sta $d012

  lda $dd00
  and #$fc
  ora #$03
  tax

  lda $d011
  and #$17
  sta $d011
  stx $dd00

  asl $d019

  lda #$15  ;screen at $6000, spr data at $63f8
  sta $d018

  lda #<up_irq3
  sta $fffe
  lda #>up_irq3
  sta $ffff
  jsr MUSIC_PLAY
  lda savea
  ldx savex
  ldy savey
  rti

up_irq3_raster = $00
up_irq3:
  sta savea
  stx savex
  sty savey
  lda #$1b
  sta $d011
up_irq4_raster = * + 1
  lda #$08
  sta $d012
  lda #<up_irq4
  sta $fffe
  lda #>up_irq4
  sta $ffff

  lda #0
  sta $d015
  lda #$03
  sta $dd00

  asl $d019
  lda savea
  ldx savex
  ldy savey
  rti

up_irq4:
  sta savea
  stx savex
  sty savey
  lda #$13
  sta $d011
up_irq1_raster = * + 1
  lda #$32
  sta $d012
  lda #<up_irq1
  sta $fffe
  lda #>up_irq1
  sta $ffff
my_d018 = * + 1
  lda #$00
  sta $d018
my_d016 = * + 1
  lda #$c8
  sta $d016
  nop
  lda #0
  sta $d020
  sta $d021
  lda $dd00
  and #$fc
  ora #$01
  sta $dd00
  lda #0
  sta $3fff
  sta $7fff
  sta $bfff

add_nSub = * + 1
  lda #0
  cmp #1
  beq .sub
;add:
  lda up_irq1_raster
  clc
  adc #$8
  cmp #$ba+8
  bne .no_stop
  lda #$ba
.no_stop:
  sta up_irq1_raster

  lda up_irq4_raster
  clc
  adc #$1
  cmp #$29
  bne .no_stop4
  lda #$28
.no_stop4:
  sta up_irq4_raster
  asl $d019
  lda savea
  ldx savex
  ldy savey
  rti

.sub:
  lda up_irq1_raster
  sec
  sbc #$8
  cmp #$1a-8
  bne .no_stop2
  lda #$1a
.no_stop2:
  sta up_irq1_raster

  lda up_irq4_raster
  sec
  sbc #$1
  cmp #$28-$14-1
  bne .no_stop5
  lda #$28-$14
.no_stop5:
  sta up_irq4_raster
  asl $d019
  lda savea
  ldx savex
  ldy savey
  rti



;###
;###
;###

framelist:
 dc.b $02,$08,$0a,$0c,$0e

framepois:
 dc.b >xtablebyte_msb,>xtablebyte_msb1,>xtablebyte_msb2,>xtablebyte_msb3,>xtablebyte_msb4


frame_rut: subroutine
  ldy this_frame
  ldx this_frame
  cpx frames
  beq .zero
  inx
  jmp .ok
.zero:
  ldx #0

.ok:
  stx this_frame
  tya
  tax
  lda my_d018
  and #$f0
  ora framelist,x
  sta my_d018

  ldx this_frame
  lda framepois,x
  sta framepoi1
  sta framepoi2
  rts

init_frame:
  lda #0
  sta this_frame
  rts

;###
;###
;###

init_scroll: subroutine
  lda #7
  sta scroll_x_lsb
  lda #0
  sta scroll_x_msb
  lda #<Screen1
  sta scr2poi
  lda #>Screen1
  sta scr2poi+1
  lda #0
  sta this_frame
  rts

scroll_x_lsb:
 dc.b 0
scroll_x_msb:
 dc.b 0
scroll_tmp:
 dc.b 0
scroll_on:
 dc.b 0

.no_scroll:
  lda #$c8
  sta my_d016
  rts

scroll_rut:
  lda scroll_on
  cmp #1
  bne .no_scroll

  lda scroll_x_lsb
  clc
  adc #1
  and #7
  sta scroll_x_lsb
  ora #$c0
  sta my_d016

  lda scroll_x_lsb
  cmp #0
  bne .no_screen_switch
  lda my_d018
  eor #$10
  sta my_d018
  and #$10
  eor #$10
  lsr
  lsr
  ora #>Screen0
  sta scr2poi+1
  lda #0
  sta scr2poi
  lda scroll_x_msb
  sec
  sbc #$10
  sta scroll_x_msb

.no_screen_switch:
;Initialize screen with characters:
  lda scroll_x_lsb
  asl
  ora scroll_x_msb
  tax
  lda #2
  sta scroll_tmp
.scr0_3:
  txa
  ldy #0
.scr0_2:
scr2poi = * + 1
  sta $8000
  inc scr2poi
  bne .nw
  inc scr2poi+1
.nw:
  clc
  adc #$10
  iny
  cpy #$28
  bne .scr0_2
  inx

;Only do 2 rows each frame
  dec scroll_tmp
  bne .scr0_3
  rts

;###
;###
;###

 seg zp
savepoi: dc.b 0
savepoi_distance: dc.b 0

frames:  dc.b 0
this_frame: dc.b 0

x1: dc.b 0
y1: dc.b 0
x2: dc.b 0
y2: dc.b 0

xnow: dc.b 0,0
ynow: dc.b 0,0

xspd: dc.b 0,0
yspd: dc.b 0,0

xtmp: dc.b 0,0
dots: dc.b 0

x1sincou: dc.b 0
y1sincou: dc.b 0
x1sinspd: dc.b 0
y1sinspd: dc.b 0
x2sincou: dc.b 0
y2sincou: dc.b 0
x2sinspd: dc.b 0
y2sinspd: dc.b 0
xacou:    dc.b 0,0
xacou_erase:    dc.b 0,0
xaspd:    dc.b 0,0

lineversion: dc.b 0
 seg code

lineversions = 12

x1cous:            dc.b $00,$00,$00,$00,$00,$80,$00,$00,$00,$20,$00,$00
x1spds:            dc.b $01,$01,$01,$01,$02,$55,$04,$00,$00,$41,$01,$00
y1cous:            dc.b $60,$40,$20,$40,$40,$c0,$40,$00,$00,$60,$20,$00
y1spds:            dc.b $04,$01,$ff,$00,$02,$55,$03,$00,$00,$42,$01,$01
x2cous:            dc.b $00,$00,$80,$00,$00,$d5,$00,$00,$00,$60,$00,$40
x2spds:            dc.b $00,$02,$01,$ff,$ff,$55,$fc,$ff,$ff,$41,$03,$01
y2cous:            dc.b $40,$40,$c0,$c0,$40,$15,$c0,$40,$40,$a0,$20,$00
y2spds:            dc.b $fd,$02,$03,$00,$ff,$55,$fc,$ff,$ff,$42,$03,$00
xaspds:            dc.b $43,$05,$00,$13,$32,$12,$34,$00,$00,$05,$00,$13
xaspds2:           dc.b $00,$01,$ff,$00,$04,$ff,$fd,$00,$ff,$fe,$03,$00
savepoi_distances: dc.b $40,$10,$1e,$2d,$2d,$3c,$1e,$82,$82,$10,$50,$1e
scroll_ons:        dc.b $00,$01,$00,$01,$00,$00,$01,$01,$01,$01,$01,$01
framess:           dc.b $00,$00,$04,$04,$04,$00,$00,$04,$04,$00,$00,$04
always_draws:      dc.b $00,$00,$01,$01,$00,$01,$01,$01,$01,$00,$00,$01


init_line:
;a is the version
  tax
  lda x1cous,x
  sta x1sincou
  lda x1spds,x
  sta x1sinspd
  lda y1cous,x
  sta y1sincou
  lda y1spds,x
  sta y1sinspd
  lda x2cous,x
  sta x2sincou
  lda x2spds,x
  sta x2sinspd
  lda y2cous,x
  sta y2sincou
  lda y2spds,x
  sta y2sinspd
  lda xaspds,x
  sta xaspd
  lda xaspds2,x
  sta xaspd+1
  lda #0
  sta xacou
  sta xacou+1
  lda savepoi_distances,x
  sta savepoi_distance
  lda scroll_ons,x
  sta scroll_on
  lda framess,x
  sta frames
  lda always_draws,x
  sta always_draw

  lda #0
  sta savepoi
  ldx #0
  lda #0
.clear_old
  sta x1_old,x
  sta y1_old,x
  sta x2_old,x
  sta y2_old,x
  sta xa_old,x
  sta xa2_old,x
  inx
  bne .clear_old
  rts


line:
  lda xacou
  clc
  adc xaspd
  sta xacou
  lda xacou+1
  adc xaspd+1
  sta xacou+1

  lda x1sincou
  clc
  adc x1sinspd
  sta x1sincou
  tax
  lda sintbl,x
  clc
  adc #$80
  sta x1

  lda y1sincou
  clc
  adc y1sinspd
  sta y1sincou
  tax
  lda sintbl,x
  clc
  adc #$80
  lsr
  sta y1

  lda x2sincou
  clc
  adc x2sinspd
  sta x2sincou
  tax
  lda sintbl,x
  clc
  adc #$80
  sta x2

  lda y2sincou
  clc
  adc y2sinspd
  sta y2sincou
  tax
  lda sintbl,x
  clc
  adc #$80
  lsr
  sta y2

  ldx savepoi
  lda x1
  sta x1_old,x
  lda y1
  sta y1_old,x
  lda x2
  sta x2_old,x
  lda y2
  sta y2_old,x
  lda xacou
  sta xa_old,x
  lda xacou+1
  sta xa2_old,x
  inx
  stx savepoi

  lda xacou
  sta xnow
  lda #0
  sta ynow
  ldx #0
  stx xspd+1
  stx yspd

;Calculate speed (distance between two dots in the line)
;The line is always drawn from left to right.
;xnow = min (x1, x2)
  lda x2
  sec
  sbc x1
  bcs .positive

;x2 is less than x1, x2 is the starting point
  lda x2
  clc
  adc xacou+1
  sta xnow+1
  ldx y2
  stx ynow+1
  lda x1
  sec
  sbc x2
  asl
  rol xspd+1 ;128 points in line
  asl
  rol xspd+1 ;64 points in line
  sta xspd
  lda y1
  sec
  sbc y2
  jmp .cont

.positive:
;x1 is less than x2, x1 is the starting point
  lda x1
  clc
  adc xacou+1
  sta xnow+1
  ldx y1
  stx ynow+1
  lda x2
  sec
  sbc x1
  asl
  rol xspd+1 ;128 points in line
  asl
  rol xspd+1 ;64 points in line
  sta xspd
  lda y2
  sec
  sbc y1

.cont:
  cmp #$80
  ror
  ror yspd ;2 points
  cmp #$80
  ror
  ror yspd ;4 points
  cmp #$80
  ror
  ror yspd ;8 points
  cmp #$80
  ror
  ror yspd ;16 points
  cmp #$80
  ror
  ror yspd ;32 points
  cmp #$80
  ror
  ror yspd ;64 points
  sta yspd+1

;Now, xnow, ynow, xspd and yspd are ok.



plot_many:
  lda #$41
  sta dots
  ldx xnow+1
  ldy ynow+1

.plot:
  lda xtablebyte_lsb,x
  sta xtmp
framepoi1 = * + 2
  lda xtablebyte_msb,x
  sta xtmp+1
  lda xtablebit,x
  ora (xtmp),y
  sta (xtmp),y

  lda xnow
  clc
  adc xspd
  sta xnow
;  lda xnow+1
  txa
  adc xspd+1
;  sta xnow+1
  tax

  lda ynow
  clc
  adc yspd
  sta ynow
;  lda ynow+1
  tya
  adc yspd+1
;  sta ynow+1
  tay
  dec dots
  bne .plot
  rts

;-------------------------------------------

line_erase: subroutine
  lda savepoi
  sec
  sbc savepoi_distance
  tax
  lda x1_old,x
  sta x1
  lda y1_old,x
  sta y1
  lda x2_old,x
  sta x2
  lda y2_old,x
  sta y2
  lda xa_old,x
  sta xacou_erase
  lda xa2_old,x
  sta xacou_erase+1
;<<<<<<<<<<<

  lda xacou_erase
  sta xnow
  lda #0
  sta ynow
  ldx #0
  stx xspd+1
  stx yspd

;Calculate speed (distance between two dots in the line)
;The line is always drawn from left to right.
;xnow = min (x1, x2)
  lda x2
  sec
  sbc x1
  bcs .positive

;x2 is less than x1, x2 is the starting point
  lda x2
  clc
  adc xacou_erase+1
  sta xnow+1
  ldx y2
  stx ynow+1
  lda x1
  sec
  sbc x2
  asl
  rol xspd+1 ;128 points in line
  asl
  rol xspd+1 ;64 points in line
  sta xspd
  lda y1
  sec
  sbc y2
  jmp .cont

.positive:
;x1 is less than x2, x1 is the starting point
  lda x1
  clc
  adc xacou_erase+1
  sta xnow+1
  ldx y1
  stx ynow+1
  lda x2
  sec
  sbc x1
  asl
  rol xspd+1 ;128 points in line
  asl
  rol xspd+1 ;64 points in line
  sta xspd
  lda y2
  sec
  sbc y1

.cont:
  cmp #$80
  ror
  ror yspd ;2 points
  cmp #$80
  ror
  ror yspd ;4 points
  cmp #$80
  ror
  ror yspd ;8 points
  cmp #$80
  ror
  ror yspd ;16 points
  cmp #$80
  ror
  ror yspd ;32 points
  cmp #$80
  ror
  ror yspd ;64 points
  sta yspd+1

;Now, xnow, ynow, xspd and yspd are ok.

  lda #$41
  sta dots
  ldx xnow+1
  ldy ynow+1

.plot:
  lda xtablebyte_lsb,x
  sta xtmp
framepoi2 = * + 2
  lda xtablebyte_msb,x
  sta xtmp+1
  lda xtablebit_erase,x
  and (xtmp),y
  sta (xtmp),y

  lda xnow
  clc
  adc xspd
  sta xnow
;  lda xnow+1
  txa
  adc xspd+1
;  sta xnow+1
  tax

  lda ynow
  clc
  adc yspd
  sta ynow
;  lda ynow+1
  tya
  adc yspd+1
;  sta ynow+1
  tay
  dec dots
  bne .plot

  rts

;-------------------------------------------

xtablebyte_lsb:
 ds.b 8,0
 ds.b 8,128
 ds.b 8,0
 ds.b 8,128
 ds.b 8,0
 ds.b 8,128
 ds.b 8,0
 ds.b 8,128
 ds.b 8,0
 ds.b 8,128
 ds.b 8,0
 ds.b 8,128
 ds.b 8,0
 ds.b 8,128
 ds.b 8,0
 ds.b 8,128
 ds.b 8,0
 ds.b 8,128
 ds.b 8,0
 ds.b 8,128
 ds.b 8,0
 ds.b 8,128
 ds.b 8,0
 ds.b 8,128
 ds.b 8,0
 ds.b 8,128
 ds.b 8,0
 ds.b 8,128
 ds.b 8,0
 ds.b 8,128
 ds.b 8,0
 ds.b 8,128

xtablebyte_msb:
 ds.b 16,>(charset+$000)
 ds.b 16,>(charset+$100)
 ds.b 16,>(charset+$200)
 ds.b 16,>(charset+$300)
 ds.b 16,>(charset+$400)
 ds.b 16,>(charset+$500)
 ds.b 16,>(charset+$600)
 ds.b 16,>(charset+$700)
 ds.b 16,>(charset+$000)
 ds.b 16,>(charset+$100)
 ds.b 16,>(charset+$200)
 ds.b 16,>(charset+$300)
 ds.b 16,>(charset+$400)
 ds.b 16,>(charset+$500)
 ds.b 16,>(charset+$600)
 ds.b 16,>(charset+$700)

xtablebyte_msb1:
 ds.b 16,>(charset1+$000)
 ds.b 16,>(charset1+$100)
 ds.b 16,>(charset1+$200)
 ds.b 16,>(charset1+$300)
 ds.b 16,>(charset1+$400)
 ds.b 16,>(charset1+$500)
 ds.b 16,>(charset1+$600)
 ds.b 16,>(charset1+$700)
 ds.b 16,>(charset1+$000)
 ds.b 16,>(charset1+$100)
 ds.b 16,>(charset1+$200)
 ds.b 16,>(charset1+$300)
 ds.b 16,>(charset1+$400)
 ds.b 16,>(charset1+$500)
 ds.b 16,>(charset1+$600)
 ds.b 16,>(charset1+$700)

xtablebyte_msb2:
 ds.b 16,>(charset2+$000)
 ds.b 16,>(charset2+$100)
 ds.b 16,>(charset2+$200)
 ds.b 16,>(charset2+$300)
 ds.b 16,>(charset2+$400)
 ds.b 16,>(charset2+$500)
 ds.b 16,>(charset2+$600)
 ds.b 16,>(charset2+$700)
 ds.b 16,>(charset2+$000)
 ds.b 16,>(charset2+$100)
 ds.b 16,>(charset2+$200)
 ds.b 16,>(charset2+$300)
 ds.b 16,>(charset2+$400)
 ds.b 16,>(charset2+$500)
 ds.b 16,>(charset2+$600)
 ds.b 16,>(charset2+$700)

xtablebyte_msb3:
 ds.b 16,>(charset3+$000)
 ds.b 16,>(charset3+$100)
 ds.b 16,>(charset3+$200)
 ds.b 16,>(charset3+$300)
 ds.b 16,>(charset3+$400)
 ds.b 16,>(charset3+$500)
 ds.b 16,>(charset3+$600)
 ds.b 16,>(charset3+$700)
 ds.b 16,>(charset3+$000)
 ds.b 16,>(charset3+$100)
 ds.b 16,>(charset3+$200)
 ds.b 16,>(charset3+$300)
 ds.b 16,>(charset3+$400)
 ds.b 16,>(charset3+$500)
 ds.b 16,>(charset3+$600)
 ds.b 16,>(charset3+$700)

xtablebyte_msb4:
 ds.b 16,>(charset4+$000)
 ds.b 16,>(charset4+$100)
 ds.b 16,>(charset4+$200)
 ds.b 16,>(charset4+$300)
 ds.b 16,>(charset4+$400)
 ds.b 16,>(charset4+$500)
 ds.b 16,>(charset4+$600)
 ds.b 16,>(charset4+$700)
 ds.b 16,>(charset4+$000)
 ds.b 16,>(charset4+$100)
 ds.b 16,>(charset4+$200)
 ds.b 16,>(charset4+$300)
 ds.b 16,>(charset4+$400)
 ds.b 16,>(charset4+$500)
 ds.b 16,>(charset4+$600)
 ds.b 16,>(charset4+$700)

xtablebit:
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01

 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01

 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01

 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01
 dc.b $80,$40,$20,$10,$08,$04,$02,$01

xtablebit_erase:
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110

 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110

 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110

 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
 dc.b %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110


;###
;###
;###

up_d000defaults:
 dc.b $00, $00, $00, $00, $00, $00, $00, $00
 dc.b $00, $00, $00, $00, $00, $00, $00, $00
 dc.b $00, $1b, $f8, $00, $00, $ff, $08, $c0
 dc.b $02, $01, $01, $00, $00, $c0, $00, $00
 dc.b $00, $00, $00, $00, $00, $00, $00, $05
 dc.b $05, $01, $01, $01, $01, $05, $05


