home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Emulation / v2600 / okiedoke / okiedoke.s < prev    next >
Text File  |  1997-02-12  |  24KB  |  900 lines

  1.      processor 6502
  2.  
  3.     include vcs.h
  4.  
  5. SCANLINE  = $80
  6. KEYDELAY  = $81
  7. COLUMN    = $82
  8. GRHEIGHT  = $83
  9. VALUE     = $84
  10. REPS      = $85
  11. MODE      = $86
  12. IGNORE    = $87
  13. BGCOLOR   = $88
  14. DRAWROW   = $89
  15. ROW       = $8A
  16. ROWBIT    = $8B
  17. GRID      = $8c ;  6 BYTES
  18. GRTABLE   = $92 ; 12 BYTES
  19. TEMPVAR   = $9E
  20. CLICK     = $9F
  21. MOVES     = $A0 ;  6 BYTES
  22. LEVEL     = $A6
  23. FIRE      = $A7
  24. WINCOUNT  = $A8
  25. SCROLL    = $A9
  26. RAND1     = $AA
  27. RAND2     = $AB
  28. RAND3     = $AC
  29. CHAR      = $AD
  30. CRTABLE   = $AE ;  12 BYTES
  31. LOGOCOLOR = $c0
  32. NOTES     = $c1
  33. DURATION  = $c5
  34.  
  35.     org  $f800
  36.  
  37. levels
  38.     .byte  $ff,$ff,$ff,$ff,$ff,$ff
  39.     .byte  $00,$50,$88,$88,$50,$00
  40.     .byte  $50,$00,$00,$00,$00,$50
  41.     .byte  $88,$50,$00,$00,$50,$88
  42.     .byte  $00,$88,$88,$88,$88,$00
  43.     .byte  $00,$00,$d8,$d8,$00,$00
  44.     .byte  $50,$d8,$88,$88,$d8,$50
  45.     .byte  $88,$50,$88,$88,$50,$88
  46.     .byte  $f8,$88,$20,$20,$88,$f8
  47.     .byte  $88,$00,$00,$00,$00,$88
  48.     .byte  $50,$d8,$d8,$d8,$d8,$50
  49.     .byte  $00,$20,$88,$88,$20,$00
  50.     .byte  $88,$f8,$70,$70,$f8,$88
  51.     .byte  $00,$00,$10,$10,$00,$00
  52.     .byte  $00,$00,$00,$00,$10,$00
  53.     .byte  $e0,$a0,$a0,$a0,$a8,$38
  54.     .byte  $00,$08,$10,$20,$00,$00
  55.     .byte  $30,$48,$a0,$48,$80,$08
  56.     .byte  $10,$00,$80,$00,$40,$10
  57.     .byte  $80,$ff,$90,$01,$90,$90
  58.     .byte  $c0,$38,$c0,$28,$50,$28
  59.     .byte  $38,$68,$b0,$48,$30,$40
  60.     .byte  $f8,$f0,$f8,$f0,$f8,$f0
  61.     .byte  $a8,$10,$a0,$08,$00,$08
  62.     .byte  $d8,$f8,$e8,$98,$78,$f8
  63.     .byte  $00,$00,$48,$10,$00,$50
  64.     .byte  $c8,$50,$40,$a0,$10,$80
  65.     .byte  $e0,$00,$c8,$30,$c0,$30
  66.     .byte  $50,$01,$30,$80,$01,$81
  67.     .byte  $10,$b0,$80,$18,$80,$78
  68.     .byte  $00,$00,$00,$00,$00,$00
  69. logo1
  70.     .byte  $00,$89,$8b,$92,$e1,$88,$8b,$f7,$03,$00,$00
  71. logo2
  72.     .byte  $00,$c9,$09,$89,$dd,$88,$00,$ff,$00,$80,$00
  73. logo3
  74.     .byte  $00,$06,$09,$a9,$46,$01,$7e,$80,$00,$00,$00
  75. logo4
  76.     .byte  $00,$14,$2a,$49,$41,$80,$00,$00,$00,$00,$00
  77. logo5
  78.     .byte  $00,$35,$49,$49,$39,$80,$00,$00,$00,$00,$00
  79. logo6
  80.     .byte  $00,$07,$0c,$aa,$47,$00,$00,$00,$00,$00,$00
  81.  
  82.     org  $f900
  83.  
  84. off1  ds  16,0
  85.  
  86. on
  87. ;smiley
  88.       .byte $00,$38,$7c,$6c,$d6,$ba,$ba,$fe,$fe,$d6,$7c,$7c,$38,$00,$00,$2a
  89. ;cat
  90.       .byte $7c,$82,$6c,$ee,$aa,$82,$ba,$44,$38,$7c,$ee,$d6,$7c,$c6,$82,$ec
  91.  
  92. ;check
  93.       .byte $18,$38,$28,$68,$c8,$88,$04,$04,$04,$04,$02,$02,$02,$01,$01,$42
  94.  
  95. ;plus
  96.       .byte $38,$38,$28,$28,$ee,$ee,$82,$82,$ee,$ee,$28,$28,$38,$38,$00,$48
  97.  
  98. ;diamond
  99.       .byte $10,$10,$28,$28,$54,$54,$ba,$ba,$54,$54,$28,$28,$10,$10,$00,$AC
  100.  
  101. ;key
  102.       .byte $10,$28,$2c,$2c,$28,$28,$2c,$28,$38,$7c,$f6,$f6,$f6,$6c,$38,$0E
  103.  
  104. ;turtle
  105.       .byte $00,$82,$92,$ba,$6c,$54,$6c,$54,$6c,$ba,$92,$aa,$28,$10,$00,$C2
  106.  
  107. ;spaceman
  108.       .byte $44,$ee,$44,$44,$82,$82,$54,$7c,$6c,$fe,$ba,$7c,$38,$00,$00,$62
  109.  
  110. crsgrp
  111.     .byte  $7c,$38,$10         ; Pattern for cursor
  112.  
  113. incchar                        ; increment random number for token
  114.     lda  RAND3
  115.     clc
  116.     adc  #$10
  117.     sta  RAND3
  118.     cmp  #$90
  119.     bne  charok
  120.     lda  #$10
  121.     sta  RAND3
  122. charok
  123.     rts
  124.  
  125. crdr                           ; cursor drawing routine
  126.     lda  #$01
  127.     sta  VDELP0
  128.     sta  VDELP1
  129. crdr2
  130.     ldy  GRHEIGHT
  131.     lda  (CRTABLE),y           ; get player0 copy1 data
  132.     sta  GRP0          
  133.     sta  WSYNC
  134.     lda  (CRTABLE+$2),y        ; get player1 copy1 data
  135.     sta  GRP1
  136.     lda  (CRTABLE+$4),y        ; get player0 copy2 data
  137.     sta  GRP0
  138.     lda  (CRTABLE+$6),y        ; get player1 copy2 data
  139.     sta  TEMPVAR
  140.     lda  (CRTABLE+$8),y        ; get player0 copy3 data
  141.     tax
  142.     lda  (CRTABLE+$A),y        ; get player1 copy3 data
  143.     tay
  144.     lda  TEMPVAR
  145.     sta  GRP1
  146.     stx  GRP0
  147.     sty  GRP1
  148.     sta  GRP0
  149.     dec  GRHEIGHT
  150.     bpl  crdr2                 ; loop until done
  151.     lda  #$0
  152.     sta  VDELP0
  153.     sta  VDELP1
  154.     sta  GRP1
  155.     sta  GRP0
  156.     sta  GRP1
  157.     rts
  158.  
  159. drw1
  160.     lda  SCANLINE              ; adjust scanline count
  161.     sbc  GRHEIGHT
  162.     sta  SCANLINE
  163.     rts
  164.                                ; clears the counter
  165. clrscore
  166.     ldy  #$5
  167. cloop
  168.     lda  #$0
  169.     sta  MOVES,y
  170.     dey
  171.     bpl  cloop
  172.     rts
  173.  
  174. pushed                         ; set up ROWBIT for updating grid
  175.     tya
  176.     clc
  177.     sbc  #$0b
  178.     tax
  179.     lda  GRID,x
  180.     eor  ROWBIT
  181.     sta  GRID,x
  182.     rts
  183.  
  184.      org   $fa00
  185.  
  186. winpat                         ; scrolling "You Win!" message
  187.     .byte  $00,$00,$00,$00,$00,$00,$80,$40,$38,$40,$80,$00,$70,$88,$88,$70
  188.     .byte  $00,$f0,$08,$08,$f0,$00,$00,$e0,$18,$30,$18,$e0,$00,$88,$f8,$88
  189.     .byte  $00,$f8,$40,$20,$10,$f8,$00,$e8,$00,$00,$00,$00,$00
  190.  
  191. playpat                        ; scrolling "Select Level" message
  192.     .byte  $00,$00,$00,$00,$00,$48,$a8,$a8,$90,$00,$f8,$a8,$88,$88,$00,$f8
  193.     .byte  $08,$08,$08,$00,$f8,$a8,$88,$88,$00,$f8,$88,$88,$88,$00,$80,$80
  194.     .byte  $f8,$80,$80,$00,$00,$f8,$08,$08,$08,$00,$f8,$a8,$88,$88,$00,$c0
  195.     .byte  $30,$08,$30,$c0,$00,$f8,$a8,$88,$88,$00,$f8,$08,$08,$08,$08,$00
  196.     .byte  $00,$00,$00,$00,$00
  197.  
  198. curs                           ; Sets CRTABLE variable to point to cursor
  199.     ldx  #$b
  200. curs1
  201.     lda  >#off1
  202.     sta  CRTABLE,x
  203.     dex
  204.     lda  <#off1
  205.     sta  CRTABLE,x
  206.     dex
  207.     bpl curs1
  208.     lda  COLUMN
  209.     clc
  210.     sbc  #$b
  211.     clc
  212.     rol
  213.     tax
  214.     lda  <#crsgrp
  215.     sta  CRTABLE,x
  216.     rts
  217.  
  218. movepat                        ; Sets grid up for current level pattern 
  219.     lda  #>levels
  220.     sta  GRTABLE+1
  221.     sty  GRTABLE
  222.     ldy  #$5
  223. resgrid
  224.     lda  (GRTABLE),y
  225.     sta  GRID,y
  226.     dey
  227.     bpl  resgrid
  228.     rts
  229.  
  230. eorgrid                        ; Combines 2 preset puzzles to make random one
  231.     lda  #>levels
  232.     sta  GRTABLE+1
  233.     lda  RAND2
  234.     sta  GRTABLE
  235.     ldy  #$5
  236. ep1
  237.     lda  (GRTABLE),y
  238.     eor  GRID,y
  239.     sta  GRID,y
  240.     dey
  241.     bpl  ep1
  242.     rts
  243.  
  244. BEGIN
  245.     lda  #$0                   ; Actual start of ROM image
  246.     tay
  247. clear
  248.     sta  $0,y                  ; Clears TIA regs and RAM (Thanks Dan!)
  249.     dey
  250.     bne  clear
  251.     ldy  #$1d
  252.     lda  #$c
  253.     sta  COLUMN                ; Reset column
  254.     lda  #$10
  255.     sta  RAND3
  256.     sta  CHAR
  257.     lda  #$c
  258.     sta  AUDC0
  259.     jsr  clrscore
  260.     lda  #$3
  261.     sta  MODE
  262.     cld
  263.     clc
  264.     jsr  incscore
  265. Start
  266.     dec  LOGOCOLOR
  267.     jsr  curs
  268.     ldx  #$ff
  269.     lda  MODE
  270.     cmp  #$1
  271.     bne  nofire
  272.     ldx  INPT4
  273. nofire
  274.     stx  FIRE
  275.     dec  CLICK
  276.     bpl  nosound
  277.     lda  #$00
  278.     sta  AUDV0
  279. nosound
  280.     lda  #$57
  281.     STA  WSYNC                 ; wait for the horizontal sync
  282.     STA  VBLANK                ; start vert blanking, enable I4 & I5 latches
  283.     STA  VSYNC                 ; start vertical retrace
  284.     LDA  #$2A
  285.     STA  TIM8T                 ; set timer for correct length
  286. Loop4
  287.     LDY  INTIM
  288.     BNE  Loop4                 ; waste some time
  289.     STY  WSYNC                 ; wait for the horizontal sync
  290.     STY  VSYNC                 ; stop vertical retrace period
  291.     LDA  #$24
  292.     STA  TIM64T                ; set timer for the big wait
  293.  
  294. ; This is the main kernal of the logic for the game
  295.  
  296.     lda  MODE
  297.     cmp  #$2        
  298.     bmi  readcons              ; if MODE = 3, then scroll intro message
  299.     bne  intro                 ; if MODE = 2, then scroll win message
  300.     jsr  playsong              ; play the winning tune
  301.     inc  BGCOLOR               ; change the background color
  302. intro
  303.     jsr  winner                ; call the scroll routine
  304.  
  305. readcons
  306.     lda  SWCHB                 ; read the console switches
  307.     ror
  308.     bcs  select                ; check Reset if not pressed go check Select
  309.     lda  RAND3                 ; get random token
  310.     sta  CHAR
  311.     ldx  #$0                   ; mute audio channel 1
  312.     sta  AUDV1
  313.     jsr  incrand               ; increase RAND1
  314.     lda  #$1
  315.     sta  MODE                  ; set mode to PLAY
  316.     lda  #$0
  317.     sta  BGCOLOR               ; set background color to black
  318.     lda  LEVEL
  319.     cmp  #$b4                  ; Level 31?
  320.     bne  rc1                   ; nope, don't create random level
  321.     lda  RAND1
  322.     cmp  RAND2                 ; if RAND1 and RAND2 are equal, increase RAND1
  323.     bne  rc3                   ; otherwise we end up with a blank puzzle!
  324.     ldx  #$0
  325.     jsr  incrand
  326. rc3 jsr  clrscore              ; reset counter
  327.     ldy  RAND1
  328.     jsr  movepat
  329.     jsr  eorgrid               ; create random puzzle
  330.     jmp  j0
  331. rc1 jsr  clrscore              ; reset counter
  332.     ldy  LEVEL                 
  333.     jsr  movepat               ; move proper level to grid
  334.     jmp  j0
  335. select
  336.     tay
  337.     ldx  #$1
  338.     jsr  incrand               ; increase RAND2
  339.     jsr  incchar               ; increase RAND3
  340.     tya
  341.     ror                        ; Check Select switch
  342.     bcs  js                    ; if not pressed go check joystick
  343.     lda  KEYDELAY              ; pressed, is the keydelay set?
  344.     bne  j0                    ; yeah, oh well, maybe next time
  345.     inc  KEYDELAY              ; nope, activate keydelay
  346.     lda  MODE                  ; are we already in select mode?
  347.     beq  selmode               ; yes, forget select mode setup
  348.     lda  #$0                   ; no, setup select mode
  349.     sta  MODE
  350.     sta  BGCOLOR               ; set background to black
  351.     lda  #$fa                  ; set level to $fa which will be inced to $00
  352.     sta  LEVEL
  353.     jsr  clrscore              ; clear counter
  354. selmode
  355.     lda  LEVEL                 ; inc level by 6 (# of bytes per puzzle)
  356.     clc
  357.     adc  #$6
  358.     cmp  #$ba                  ; did we hit level 32 yet?
  359.     bne  notlast               ; nope, don't set level to 1
  360.     jsr  clrscore              ; yep, set level to 1
  361.     lda  #$0
  362. notlast
  363.     sta  LEVEL                 
  364.     tay
  365.     jsr  movepat               ; move level pattern to grid
  366.     jsr  incscore              ; increment counter
  367.     jmp  Loop3                 ; start drawing the screen
  368. js
  369.     ldy  #$f0                  ; load dummy into y incase not in play mode
  370.     lda  MODE                  ; Are we in PLAY mode?
  371.     cmp  #$1
  372.     bne  nojs                  ; nope, don't read joystick
  373.     lda  SWCHA                 ; read joystick
  374.     and  #$f0
  375.     tay
  376. nojs
  377.     cpy  #$f0                  ; if bits 4-7 = 1 in SWCHA, js not moved
  378.     bne  j0
  379.     lda  FIRE                  ; see if fire button was pressed
  380.     bpl  j0                    ; yes, go check keydelay
  381.     lda  #$0                   ; nope, clear keydelay
  382.     sta  KEYDELAY              ; if nothing pressed, reset keydelay
  383.     jmp  b10                   ; b10 too far away for a beq :(
  384. j0
  385.     ldx  KEYDELAY              
  386.     inc  KEYDELAY              ; increment keydelay
  387.     cpx  #$00                  ; was old keydelay 0?
  388.     beq  joa                   ; yeah, lets check the fire button again
  389.     cpx  #$10                  ; nope, was old keydelay $10?
  390.     beq  job                   ; yeah, o.k. we can check the fire button
  391.     jmp  Loop3                 ; nope, forget the fire button, draw screen
  392. job lda  #$0                   
  393.     sta  KEYDELAY              ; reset keydelay
  394.     bne  joa                   ; hmm, this doesn't seem to do anything :^|
  395.     jmp  Loop3                 ; could probably use beq Loop3 if in range
  396. joa lda  FIRE                  ; check fire button again
  397.     bpl  b6                    ; ahh, it's been pushed, let's go do something
  398.     tya                        ; get joystick reading from y
  399.     asl                        ; check the "right" bit
  400.     bcs  j2                    ; nope, go check "left" bit
  401.     ldy  COLUMN                ; move cursor right
  402.     iny
  403.     cpy  #$12                  ; did we move past the last column?
  404.     bne  j1                    ; nah, we're ok
  405.     ldy  #$c                   ; yep, reset to first column
  406. j1  sty  COLUMN
  407. j2  asl                        ; check the "left" bit
  408.     bcs  j4                    ; nope, go check "down" bit
  409.     ldy  COLUMN                ; move cursor left
  410.     dey
  411.     cpy  #$b                   ; did we go too far left?
  412.     bne  j3                    ; nope
  413.     ldy  #$11                  ; yeah, set pointer to column 6
  414. j3  sty  COLUMN
  415. j4
  416.     asl                        ; check the "down" bit
  417.     bcs  j5                    ; nope, go check "up" bit
  418.     inc  ROW                   ; move cursor down
  419.     lda  ROW
  420.     cmp  #$5                   ; did we go too far down?
  421.     bne  b6                    ; nope
  422.     lda  #$0                   ; yeah, set row to top row
  423.     sta  ROW
  424.     jmp  b6
  425. j5  asl                        ; check the "up" bit
  426.     bcs  b6                    ; nope, check the fire button
  427.     dec  ROW                   ; move pointer up
  428.     bpl  b6                    ; did we go too far up? nope!
  429.     ldy  #$4                   ; yep! set row to bottom row
  430.     sty  ROW 
  431. b6
  432.     lda  FIRE                  ; check for fire button
  433.     and  #$80
  434.     bne  b10                   ; not pressed, draw screen
  435.     jsr  incscore              ; pressed, increase "moves" counter
  436. b6a 
  437.     ldx  ROW                   ; invert "plus" pattern
  438.     inx
  439.     lda  eorpat,x
  440.     sta  ROWBIT
  441.     ldy  COLUMN
  442.     jsr  pushed
  443.     ldx  ROW
  444.     inx
  445.     lda  bitpat,x
  446.     sta  ROWBIT
  447.     iny
  448.     cpy  #$6
  449.     beq  ps1
  450.     jsr  pushed
  451. ps1 dey
  452.     dey
  453.     bmi  b10
  454.     jsr  pushed
  455.     ldy  #$5
  456.     sty  TEMPVAR
  457. checkwin                       ; routine to see if puzzle is solved
  458.     lda  GRID,y
  459.     and  #$f8
  460.     beq  colok
  461.     lda  #$0
  462.     sta  TEMPVAR
  463. colok
  464.     dey
  465.     bpl  checkwin
  466.     lda  TEMPVAR
  467.     beq  keepon                ; no, stay in PLAY mode
  468.     lda  #$2                   ; YES! the puzzle is solved
  469.     sta  MODE
  470.     lda  #$0a                  ; set number of notes to $a
  471.     sta  NOTES
  472.     sta  DURATION              ; set duration for small pause befor song
  473.     lda  #$4                   ; set type of tone to play on aud channel 1
  474.     sta  AUDC1
  475.     lda  #$0                   ; reset scrolling message counter
  476.     sta  SCROLL
  477.     sta  BGCOLOR               ; set background color to black
  478. keepon
  479.  
  480. b10
  481.  
  482. Loop3
  483.     lda  BGCOLOR               ; start of screen rendering routine
  484.     sta  COLUBK                ; set background color
  485. Loop3a
  486.     LDY  INTIM
  487.     BNE  Loop3a                ; waste time
  488.     STY  WSYNC                 ; wait for horizontal sync
  489.     ldy  #$04
  490.     STY  VBLANK                ; end vertical blanking
  491.     sty  WSYNC
  492.     lda  #$75                  ; set number of scanlines
  493.     sta  SCANLINE
  494.     sta  WSYNC
  495.     lda  #$00                  ; clear background
  496.     sta  PF0
  497.     sta  PF1
  498.     sta  PF2
  499.     sta  REFP0
  500.     sta  HMP1                  ; move player 1 right 7 pixels
  501.  
  502. loop6
  503.     stx  WSYNC
  504.     ldx  SCANLINE
  505.     ldy  #$0
  506.     sty  DRAWROW               ; reset drawrow variable
  507.     cpx  #$75                  ; top of screen?
  508.     bne  tb1                   ; no, get outta here!
  509.     lda  #$84                  ; set playfield color
  510.     sta  COLUPF
  511.     lda  #$1                   ; set playfield control
  512.     sta  CTRLPF
  513.     lda  BGCOLOR               ; set token color to background color
  514.     sta  COLUP0
  515.     sta  COLUP1
  516.  
  517. okie                           ; copies addrs to zero-page for RetroWare
  518.     ldx  #$0b       
  519. okie7
  520.     lda  oktbl,x
  521.     sta  GRTABLE,x
  522.     dex
  523.     bpl  okie7
  524.     jsr  drawit                ; set up draw routine
  525.     lda  #$ff
  526.     sta  PF2
  527.     ldy  #$6                   ; set height of graphic to draw
  528.     sty  GRHEIGHT
  529.     lda  #$18                  ; set color for graphic
  530.     sta  COLUP0
  531.     sta  COLUP1
  532.     jsr  loop2a                ; go draw "Okie Dokie"
  533.     ldx  #$71
  534.     stx  SCANLINE              ; fudge scanline #
  535. tb1
  536.     cpx  #$71                  ; top of grid?
  537.     bne  tb2                   ; nope, get outta here!
  538.     lda  #$01                  ; yeah, set side borders for puzzle
  539.     sta  PF2
  540.     lda  #>off1                ; put high-byte of graphics in GRTABLE
  541.     ldy  #$d
  542. tb1a
  543.     sta  GRTABLE,y
  544.     dey
  545.     dey
  546.     bpl  tb1a
  547.     jmp  b4
  548. tb2 iny
  549.     cpx  #$70                  ; if at scanline #$70 set up row 1
  550.     beq  b0
  551.     iny
  552.     cpx  #$60                  ; set up row 2
  553.     beq  b0
  554.     iny
  555.     cpx  #$50                  ; set up row 3
  556.     beq  b0
  557.     iny
  558.     cpx  #$40                  ; set up row 4
  559.     beq  b0
  560.     iny
  561.     cpx  #$30                  ; set up row 5
  562.     beq  b0
  563.     iny
  564.     cpx  #$20                  ; set up row 6
  565.     bne  b4
  566.     sty  DRAWROW               ; set up and draw "RetroWare"
  567.     lda  #$ff
  568.     sta  PF2
  569.     jsr  name
  570.     lda  #$8
  571.     sta  GRHEIGHT
  572.     jsr  loop2a
  573.     lda  #$0
  574.     sta  PF2
  575.     jsr  mv
  576.     ldy  #$9
  577.     bne  bb    
  578. b0  sty  DRAWROW               
  579.     jsr  code
  580.     ldy  #$e
  581. bb  sty  GRHEIGHT
  582.     ldx  CHAR
  583.     lda  on-1,x                ; get token color and set it
  584.     sta  COLUP0
  585.     sta  COLUP1
  586.     jsr  drw1
  587.     jsr  loop2a                ; actually draw token row
  588. b1
  589.     lda  BGCOLOR
  590.     ldx  DRAWROW
  591.     DEX
  592.     cpx  ROW                   ; should we draw the cursor?
  593.     bne  bb3                   ; nope (we still draw it but in bg color)
  594.     lda  #$43                  ; set cursor color
  595. bb3 
  596.     sta  COLUP0
  597.     sta  COLUP1
  598.     ldy  #$2                   ; set up cursor height
  599.     sty  GRHEIGHT
  600.     jsr  crdr                  ; actually draw cursor
  601. b4  dec  SCANLINE              ; are we done with the screen yet?
  602.     beq  b4a                   ; YES! Thank God! let's start over.
  603.     jmp  loop6                 ; nope, go to the next scanline
  604. b4a
  605.     jmp  Start
  606.  
  607.  
  608. drawit
  609.     lda  #$03                  ; set both players to 3 copies
  610.     sta  NUSIZ0
  611.     sta  NUSIZ1
  612.     ldx  #$6                   ; move players 12 columns over
  613.     ldy  #$0
  614.     sta  WSYNC                 ; wait for scanline
  615. loop1
  616.     dex                        ; wait for column (15 bit wide) x
  617.     bpl  loop1
  618.     nop                        ; additional delay
  619.     sta  RESP0                 ; reset player 0
  620.     sta  RESP1                 ; reset player 1
  621.     lda  #$d0                  ; set player 0 to move left 1 pixel
  622.     sta  HMP0
  623.     lda  #$e0
  624.     sta  HMP1
  625.     sta  WSYNC
  626.     sta  HMOVE                 ; move player 0
  627.  
  628. loop2a
  629.     lda  #$01
  630.     sta  VDELP0
  631.     sta  VDELP1
  632. loop2
  633.     ldy  GRHEIGHT
  634.     lda  (GRTABLE),y           ; get player0 copy1 data
  635.     sta  GRP0          
  636.     sta  WSYNC
  637.     lda  (GRTABLE+$2),y        ; get player1 copy1 data
  638.     sta  GRP1
  639.     lda  (GRTABLE+$4),y        ; get player0 copy2 data
  640.     sta  GRP0
  641.     lda  (GRTABLE+$6),y        ; get player1 copy2 data
  642.     sta  TEMPVAR
  643.     lda  (GRTABLE+$8),y        ; get player0 copy3 data
  644.     tax
  645.     lda  (GRTABLE+$A),y        ; get player1 copy3 data
  646.     tay
  647.     lda  TEMPVAR
  648.     sta  GRP1
  649.     stx  GRP0
  650.     sty  GRP1
  651.     sta  GRP0
  652.     dec  GRHEIGHT
  653.     bpl  loop2                 ; loop until done
  654.     lda  #$0
  655.     sta  VDELP0
  656.     sta  VDELP1
  657.     sta  GRP1
  658.     sta  GRP0
  659.     sta  GRP1
  660.     rts
  661.                                
  662. okie1                          ; Graphics for "Okie Dokie"
  663.     .byte  $00,$71,$89,$89,$89,$89,$70
  664. okie2
  665.     .byte  $00,$29,$4b,$8a,$41,$28,$00
  666. okie3
  667.     .byte  $00,$c0,$00,$80,$c0,$00,$00
  668. okie4
  669.     .byte  $00,$f0,$89,$89,$88,$88,$f0
  670. okie5
  671.     .byte  $00,$e4,$15,$16,$e5,$04,$00
  672. okie6
  673.     .byte  $00,$a7,$2c,$2a,$07,$a0,$00
  674.  
  675. table2                         ; Address table for "RetroWare"
  676.     .byte  <logo1
  677.     .byte  >logo1
  678.     .byte  <logo2
  679.     .byte  >logo2
  680.     .byte  <logo3
  681.     .byte  >logo3
  682.     .byte  <logo4
  683.     .byte  >logo4
  684.     .byte  <logo5
  685.     .byte  >logo5
  686.     .byte  <logo6
  687.     .byte  >logo6
  688.  
  689. name                           ; copies addresses to zero-page for RetroWare
  690.     lda  LOGOCOLOR
  691.     sta  COLUP0
  692.     sta  COLUP1
  693.     ldx  #$0b       
  694. loop7
  695.     lda  table2,x
  696.     sta  GRTABLE,x
  697.     dex
  698.     bpl  loop7
  699.     rts
  700.  
  701. ;bit-mapped graphics of digits
  702.  
  703.     org  $fe00
  704.  
  705. d0    .byte  $00,$00,$38,$44,$44,$44,$44,$44,$44,$38,$0,$0,$0,$0,$0,$0
  706. d1    .byte  $00,$00,$10,$10,$10,$10,$10,$10,$30,$10,$0,$0,$0,$0,$0,$0
  707. d2    .byte  $00,$00,$7c,$40,$40,$30,$08,$04,$44,$38,$0,$0,$0,$0,$0,$0
  708. d3    .byte  $00,$00,$38,$44,$44,$04,$18,$04,$44,$38,$0,$0,$0,$0,$0,$0
  709. d4    .byte  $00,$00,$04,$04,$7e,$44,$24,$14,$0c,$04,$0,$0,$0,$0,$0,$0
  710. d5    .byte  $00,$00,$38,$44,$44,$04,$78,$40,$40,$7c,$0,$0,$0,$0,$0,$0
  711. d6    .byte  $00,$00,$38,$44,$44,$78,$40,$40,$44,$38,$0,$0,$0,$0,$0,$0
  712. d7    .byte  $00,$00,$20,$20,$10,$10,$08,$08,$04,$78,$0,$0,$0,$0,$0,$0
  713. d8    .byte  $00,$00,$38,$44,$44,$44,$38,$44,$44,$38,$0,$0,$0,$0,$0,$0
  714. d9    .byte  $00,$00,$38,$44,$04,$3c,$44,$44,$44,$38,$0,$0,$0,$0,$0,$0
  715. dl    .byte  $00,$fc,$80,$80,$80,$80,$80,$80,$80,$80,$0,$0,$0,$0,$0,$0
  716. dv    .byte  $00,$10,$28,$28,$44,$44,$82,$82,$82,$82,$0,$0,$0,$0,$0,$0
  717. off    ds 16,0
  718.  
  719. code
  720.     sta  WSYNC
  721.     ldx  DRAWROW
  722.     lda  bitpat,x
  723.     sta  ROWBIT
  724.  
  725.     ldx  #$0d                  ; sets up addresses
  726.     ldy  #$6                   ; for drawing the row of tokens
  727. code1                          
  728.     lda  GRID,y
  729.     and  ROWBIT
  730.     bne  cd2
  731.     lda  #<off1
  732.     beq  cd3
  733. cd2 lda  CHAR
  734. cd3 sta  GRTABLE-1,x
  735.     dex
  736.     dex
  737.     dey
  738.     bpl  code1
  739.     rts
  740.  
  741. mv                             ; sets up addresses in zero-page locations
  742.     ldx  #$0b                  ; for drawing the 6-digit code for displaying
  743.     ldy  #$5                   ; the number of moves executed.
  744. mv1
  745.     lda  #$fe
  746.     sta  GRTABLE,x
  747.     lda  MOVES,y
  748.     sta  GRTABLE-1,x
  749.     dex
  750.     dex
  751.     dey
  752.     bpl  mv1
  753.     lda  #<off
  754.     sta  GRTABLE
  755.     ldy  MODE
  756.     bne  mv2
  757.     lda  #<dl
  758.     sta  GRTABLE
  759.     sta  GRTABLE+4
  760.     lda  #<dv
  761.     sta  GRTABLE+2
  762. mv2 lda  #<off
  763.     sta  GRTABLE+10
  764.     cpy  #$3
  765.     bne  mv3
  766.     sta  GRTABLE+2
  767.     sta  GRTABLE+4
  768.     sta  GRTABLE+6
  769.     sta  GRTABLE+8
  770. mv3 rts
  771.  
  772. bitpat                         ; bit look up table
  773.    .byte $00,$80,$40,$20,$10,$08
  774. eorpat                         ; inverting look up table
  775.    .byte $00,$c0,$e0,$70,$38,$1c
  776.  
  777. winner                         ; scrolling message routine
  778.     inc  WINCOUNT
  779.     lda  WINCOUNT
  780.     cmp  #$8
  781.     bne  endwin
  782.     lda  #$0
  783.     sta  WINCOUNT
  784.     lda  #>playpat
  785.     sta  GRTABLE+1
  786.     lda  #<playpat
  787.     ldy  MODE
  788.     cpy  #$3
  789.     beq  play
  790.     lda  #>winpat
  791.     sta  GRTABLE+1
  792.     lda  #<winpat
  793. play
  794.     clc
  795.     adc  SCROLL
  796.     sta  GRTABLE
  797.     ldy  #$5
  798. reswin
  799.     lda  (GRTABLE),y
  800.     sta  GRID,y
  801.     dey
  802.     bpl  reswin
  803.     inc  SCROLL
  804.     lda  #$27
  805.     ldy  MODE
  806.     cpy  #$2
  807.     beq  win
  808.     lda  #$40
  809. win cmp  SCROLL
  810.     bne  endwin
  811.     lda  #$0
  812.     sta  SCROLL
  813. endwin
  814.     rts
  815.  
  816. incscore                       ; increment counter
  817.     lda  #$ff
  818.     sta  AUDV0
  819.     lda  #$10
  820.     sta  CLICK
  821.     sed
  822.     ldx  #$4
  823. digloop
  824.     lda  MOVES,x
  825.     clc
  826.     adc  #$10
  827.     sta  MOVES,x
  828.     cmp  #$0
  829.     bne  isexit
  830.     dex
  831.     cpx  #$00
  832.     bne  digloop
  833. isexit
  834.     cld
  835.     rts
  836.  
  837. incrand                        ; increment random number
  838.     lda  RAND1,x
  839.     clc
  840.     adc  #$6
  841.     sta  RAND1,x
  842.     cmp  #$b4
  843.     bne  randok
  844.     lda  #$0
  845.     sta  RAND1,x
  846. randok
  847.     rts
  848.  
  849. playsong                       ; routine to play a song
  850.     lda  NOTES
  851.     bmi  songoff
  852.     dec  DURATION
  853.     lda  DURATION
  854.     cmp  #$4
  855.     beq  songoff
  856.     cmp  #$0
  857.     bne  songexit
  858.     dec  NOTES
  859.     bmi  songexit
  860.     lda  #$8
  861.     sta  AUDV1
  862.     ldx  NOTES
  863.     lda  dur,x
  864.     sta  DURATION
  865.     lda  freq,x
  866.     sta  AUDF1
  867. songexit
  868.     rts
  869. songoff
  870.     lda  #$0
  871.     sta  AUDV1
  872.     rts
  873.  
  874. oktbl                          ; address table for "Okie Dokie"
  875.     .byte  <okie1
  876.     .byte  >okie1
  877.     .byte  <okie2
  878.     .byte  >okie2
  879.     .byte  <okie3
  880.     .byte  >okie3
  881.     .byte  <okie4
  882.     .byte  >okie4
  883.     .byte  <okie5
  884.     .byte  >okie5
  885.     .byte  <okie6
  886.     .byte  >okie6
  887.  
  888. dur                            ; duration values for song notes
  889.     .byte $20,$09,$09,$20,$18,$18,$18,$18,$09,$09
  890. freq                           ; frequency values for song notes
  891.     .byte $0e,$10,$12,$14,$11,$10,$11,$10,$12,$13
  892.  
  893.     dc.b $a9,"RetroWare"       ; copyright notice
  894.  
  895.     org  $fffc
  896.     .byte  <BEGIN              ; set ROM entry point
  897.     .byte  >BEGIN
  898.     .byte  <BEGIN              ; set INTERRUPT vector
  899.     .byte  >BEGIN
  900.