; ; Csabo's 1K Racer ; Written by Csaba Pankaczy ; aka. Csabo/LOD ; ; Finished 2002.09.14 ; ; Variables ; road = $D0 ; road pointer counter within RoadData roads = $9E ; road pointer counter within current section rdsec = $D2 ; word: current section road rd1 = $D4 ; helper variable, when drawing more than one char: char rd2 = $D5 ; helper variable, when drawing more than one char: count rdcol = $D6 ; helper when drawing: color hsc = $D7 ; variable: (h)orizontal (sc)roll (goes to ff07) speed = $D8 ; variable: speed of scrolling ($00-$20) crash = $D9 ; flag: 0 = no crash; otherwise crashed sectcnt = $DA ; section repeat counter ; readchr = $DC ; word: when reading actual road data copyf = $DE ; word: to copy memory areas from copyt = $3B ; word: to copy memory areas to ; it must be $3B vector: ROM routine $9223 uses it ; carpos1 = $EA ; word: position of car in charater mem ; also: $EA will mean NOP!!! carpos2 = $EC ; word: position of car in color mem ; ; constants ; CarsPos = $0C06 ; position of number of cars on screen ScorePos = $0C22 ; position of score on screen ; CHROUT = $DC49 ; ; ------------------------------------------------------- ; Start from $1001, normal basic start ; ORG $1001 - 2 DW $1001 ; loader address for PRG file ; ; --- These four bytes will serve as ; next line link and line number ; DW $100D,2002 ; DB $9E ; SYS Command DB "4242" DB 0,0,0 ; ; --- ; SectionWrap STA road ; reset road counter ; INC CarsPos ; extra car awarded ; DB $2C SectionEnd INC road LDX road LDA RoadData,X BEQ SectionWrap STA rdsec LDA #$00 STA roads RTS ; ; --- ; CarInit LDA #($0C00 + 12 * 40 + 0) >> 8 STA carpos1+1 AND #$0B STA carpos2+1 ; LDA #($0C00 + 12 * 40 + 0) & 255 ; DB $2C ; this will skip the next two bytes ; then "carpos1" is = $EA ; which is a NOP, so 3 bytes are skipped ; CarAdd CLC ADC carpos1 carinit2 STA carpos1 STA carpos2 ; RTS ; ; --- ; CarClear LDY #$01 LDA #$A0 STA (carpos1),y put1 DEY STA (carpos1),y ret1 RTS ; ; --- ; CarSave LDA #$51 STA $FF15 ; LDY #$01 LDA (carpos1),y ; CMP #$A0 ; space? BEQ ok1 ; ; --- crashed! ; LDX #$01 STX speed ; LDX #$12 STX crash STX $FF15 ; DEC CarsPos LDA CarsPos CMP #$30 BNE ret1 ; ; *** Game Over *** ; LDX #9 go1 LDA GameOverText,x STA $0F57,x DEX BPL go1 GameOver INC $FF15 ; do something to show game is over... ; JSR $CF11 ; Check Run/Stop BMI GameOver ; if $80 is set, Run/Stop is not pressed JMP Start ; Restart! ; ok1 DEY LDA #$16 ; set car's color STA (carpos2),y INY STA (carpos2),y ; LDA hsc ; character representing the car LSR a ORA #$41 ; $40/$41 , $42/$43 etc. STA (carpos1),y SEC SBC #$01 BNE put1 ; always jump ; Sync CMP $FF1D BNE Sync RTS ; ; --- ; Start SEI LDA #$1E ; green JSR CHROUT ; chrout JSR $C567 ; clear screen - SCNCLR ; ; *** Char-set init ; LDA #$D0 ; FROM $D000 STA copyf+1 ; JSR $C7E8 ; ROM: STA $FF12, LDA #$00, STA $83, RTS ; A = 0 ; ;--- TAY STY copyf STY copyt ; ;JSR $9F2B : LDA #$00, STA $61, STA $66 ; STY hsc STY crash STY sectcnt ; JSR SectionWrap ; A must be zero for this call ; ;--- ; LDA #$38 ; TO $3800 STA copyt+1 STA $FF13 ; ; --- copy ROM charset ; LDX #$07 ; 8 * 256 bytes to copy copyloop LDA (copyf),y EOR #$FF ; invert all chars STA (copyt),y INY BNE copyloop ; INC copyf+1 ; next 256 bytes INC copyt+1 ; DEX BPL copyloop ; ; --- speed, car init ; INY ; y=0+1 STY speed ; y=1 ; JSR CarInit ; ; --- ; ;LDA #$00 ;STA copyf LDA #$10 ; low LDY #$3A ; high STY copyf+1 ; JSR $9223 ; $3B = A, $3C = Y (or STA copyt, sty copyt+1) ;STA copyt ;STY copyt+1 ; k3 LDY #$0F ; k2 LDA CharCar-8,y ; copy original char too STA $3A00,y ; LDA (copyf),y ; copy current frame to next frame STA (copyt),y DEY BPL k2 ; LDA copyt STA copyf CLC ADC #$08 STA copyt ; LDY #$07 ; left shift current frame k1 LDA (copyt),y ASL A STA (copyt),y LDA (copyf),y ROL A STA (copyf),y DEY BPL k1 ; LDA copyt CLC ADC #$08 STA copyt ; BPL k3 ; stops at $3A80 (after 8 frames) ; ; *** Screen init ; LDX #5 * 40 LDA #$A0 ; space la1 STA $0C00 + 10 * 40,x DEX BNE la1 ; LDA #$33 STA CarsPos ; LDX #$04 la2 LDA CarsText-1,x STA $0c00,x LDA ScoreText,x STA $0C1C,x LDA #$30 STA ScorePos,x DEX BPL la2 ; LDX #$12 STX rdsec+1 INX STX readchr+1 ; ; --- screen color init ; JSR CarSave ; set background color ; LDA #$35 STA $FF19 STA rdcol ; ; ################# ; *** GAME LOOP *** ; ################# ; l2 LDA #$23 JSR Sync ; LDA hsc LSR a LSR a STA $FF07 ; LDA #$AC JSR Sync ; LDA #$00 STA $FF07 ; LDA crash BNE skip2 ; JSR CarClear ; always restore char under the car ; skip2 LDA hsc SEC SBC speed CMP #$20 BCS l5 ; STA hsc ; LDA crash BNE skip3 ; JSR CarSave ; skip3 LDA #$24 JSR Sync ; l2a BEQ l2 ; always jump ; ; --- ; l5 CLC ADC #$20 STA hsc ; LDX speed INX CPX #$11 ; over max speed? BNE sp1 LDX #$10 ; max speed sp1 STX speed ; LDA crash BNE skip1 ; JSR CarSave ; ; --- inc score ; LDX #$04 ; start at last digit scr2 INC ScorePos,x ; increment one digit LDA ScorePos,x ; check digit CMP #$3A ; >9? BNE scr1 LDA #$30 ; yes, replace with zero STA ScorePos,x DEX ; and increment previous digit BPL scr2 scr1 ; ; --- remove car from screen ; JSR CarClear ; ; --- keyboard check ; LDA #$DF JSR $DB70 ; keyboard ROM routine AND #$09 ; check 4th and 1st bits CMP #$01 ; cursor up only? BEQ key1 CMP #$08 ; cursor down only BNE key2 ; ; down ; LDA #$28 + $28 ; add 80! then we run into the up routine... JSR CarAdd ; BCC key1 INC carpos1+1 INC carpos2+1 key1 ; ; up ; LDA #$D8 ; sub 40 JSR CarAdd ; BCS key2 DEC carpos1+1 DEC carpos2+1 key2 ; ; --- copy screen one char to the left ; skip1 LDY #$00 ; y=0 l3 LDA $0801 + 05 * 40,y STA $0800 + 05 * 40,y LDA $0801 + 10 * 40,y STA $0800 + 10 * 40,y LDA $0801 + 15 * 40,y STA $0800 + 15 * 40,y ; LDA $0c01 + 05 * 40,y STA $0c00 + 05 * 40,y LDA $0c01 + 10 * 40,y STA $0c00 + 10 * 40,y LDA $0c01 + 15 * 40,y STA $0c00 + 15 * 40,y ; INY CPY #5 * 40 - 1 BNE l3 ; ; --- after crash ; LDY crash BEQ d1 ; zero? skip all this, and just draw car ; DEY d2 STY crash BNE d3 ; jump if not yet zero ; ; if zero, we'll try to restart ; JSR CarInit ; reset car ; LDY #$07 ; y=1 d01 LDA (carpos1),y ; check char in fron of car CMP #$A0 ; space? BNE d2 ; if not, reset "crash" to one ; otherwise crash stays on zero, and we're playing DEY BNE d01 ; d1 JSR CarSave d3 ; ; --- *************************** ; SectionRead LDA sectcnt ; is section counter zero already? BNE sectdec ; if not, we won't read a new byte yet ; LDY roads INC roads LDA (rdsec),y BNE sectread ; non zero? ; ; --- wrap JSR SectionEnd ; new section BEQ SectionRead ; always jump ; sectread CMP #$10 ; > $10 ? BCS sectdat ; yes, real data ; STA sectcnt ; no, it's a counter ; DB $2C ; skip next instruction sectdat STA readchr ; DB $2C sectdec DEC sectcnt ; DrawLine2 ; ; --- ; LDA #( $0C27 + 5 * 40 ) & 255 ; starting address of draw STA vline1+1 STA vline2+1 LDA #( $0C27 + 5 * 40 ) >> 8 STA vline1+2 AND #$0B STA vline2+2 ; LDY #$00 l7 ; LDX #$01 ; 1 repeats by default LDA (readchr),Y ; self modifying code STA rd1 ; store character ; BNE draw_char ; non-zero? ; ; --- zero flag: set color byte follows ; INY LDA (readchr),y ; get next byte STA rdcol ; store the color BNE l10 ; always jump ; draw_char CMP #$B0 BCS l8 CMP #$80 BCC l8 ; ; --- it's compression flag ; CMP #$90 BCC l8a LDX #$A0 ; space DB $2C l8a LDX #$20 ; block STX rd1 ; character AND #$0F TAX ; ; --- perform 'uncompress' ; l8 LDA rd1 ; char vline1 STA $0C00 ; self-mod LDA rdcol ; color vline2 STA $0800 ; self-mod ; LDA vline1+1 ; down one line CLC ADC #$28 STA vline1+1 STA vline2+1 BCC vlinedown1 INC vline1+2 INC vline2+2 vlinedown1 ; DEX BNE l8 ; l10 INY LDA vline1+1 CMP #( $0c27 + 20 * 40 ) & 255 BNE l7 ; ; --- ; JMP l2a ; ### ### ### END OF GAME LOOP ### ### ### ; ;--------------------------------------------------------- ; ; ; --- ; ; " CAR" (S) CarsText DB $03,$01,$12 ;$13 ScoreText ; "SCORE" DB $13,$03,$0F,$12,$05 ; GameOverText ; "GAME OVER" DB $7,$1,$D,$5,$20,$20,$F,$16,$5,$12 ; ; ####################################################################### ; ; *************************************************** ; Stop = $00 ; SectionStraight DB Narrow & 255,$07,Stop ; SectionTrees DB Trees1 & 255, RoadWide & 255, Trees2 & 255 DB RoadWide & 255, Trees3 & 255 ; SectionWide DB RoadWide & 255,$07,Stop ; SectionMiddle DB RoadK1 & 255,RoadK2 & 255,$04,RoadK3 & 255,Stop ; SectionMiddle2 DB RoadK4 & 255,RoadK5 & 255,$04,RoadK6 & 255,Stop ; SectionDown DB RoadDn0 & 255,RoadDn1 & 255,RoadDn2 & 255,RoadDn3 & 255,RoadDn4 & 255 SectionDown2 DB RoadDn5 & 255,RoadDn6 & 255,RoadDn7 & 255,RoadDn8 & 255,RoadDn9 & 255,Stop ; SectionBot DB RoadBot & 255,$0C,Stop ; SectionClose DB Road1 & 255,Road2 & 255,Road3 & 255,Road4 & 255,Road5 & 255,Stop ; SectionFel DB RoadUp0 & 255,RoadUp1 & 255,RoadUp2 & 255,RoadUp3 & 255,RoadUp4 & 255,Stop SectionFel2 DB RoadUp5 & 255,RoadUp6 & 255,RoadUp7 & 255,RoadUp8 & 255,RoadUp9 & 255,Stop ; SectionOpen DB Road2a & 255,Road3a & 255,Road4a & 255,Road5a & 255,Road6a & 255,Stop ; SectionStartLine DB RoadC1 & 255,RoadC & 255 DB RoadC2 & 255,RoadC & 255 DB RoadC3 & 255,RoadC & 255 DB RoadC2 & 255,RoadC & 255 DB RoadC1 & 255,RoadC & 255,Stop ; SectionBar DB Road8 & 255,Road8b & 255,Road8a & 255,Road8r & 255,Road8 & 255,Stop ; SectionBuilding DB Buildng & 255, $07, Stop ; SectionRiver DB River1 & 255, River2 & 255, $05, River1 & 255, Stop ; SectionRiver2 DB River3 & 255, River4 & 255, $09, River3 & 255, Stop ; SectionCorner DB Corner1 & 255, Corner2 & 255, Stop ; ; ; CharCar DB $66,$FF,$81,$A5,$A5,$81,$FF,$66 ; car ; RoadData DB SectionOpen & 255 DB SectionStartLine & 255 DB SectionWide & 255 DB SectionRiver2 & 255 DB SectionWide & 255 DB SectionTrees & 255 DB SectionClose & 255 DB SectionStraight & 255 DB SectionBuilding & 255 DB SectionStraight & 255 DB SectionDown2 & 255 DB SectionBot & 255 DB SectionCorner & 255 DB SectionWide & 255 DB SectionTrees & 255 DB SectionRiver2 & 255 DB SectionWide & 255 DB SectionClose & 255 DB SectionStraight & 255 DB SectionOpen & 255 DB SectionWide & 255 DB SectionRiver & 255 DB SectionClose & 255 DB SectionDown2 & 255 DB SectionBot & 255 DB SectionFel & 255 DB SectionStraight & 255 DB SectionDown2 & 255 DB SectionBot & 255 DB SectionFel & 255,SectionFel2 & 255 DB SectionDown & 255, SectionFel & 255 DB SectionStraight & 255, SectionBar & 255, SectionStraight & 255 DB SectionOpen & 255, SectionWide & 255 DB SectionMiddle2 & 255, SectionWide & 255 DB SectionMiddle & 255, SectionWide & 255 DB SectionRiver & 255, SectionWide & 255 DB SectionClose & 255 DB SectionStraight & 255 DB SectionOpen & 255 DB SectionMiddle & 255 DB SectionClose & 255 DB SectionBar & 255 DB SectionStraight & 255 DB SectionDown2 & 255, SectionFel & 255 DB SectionBuilding & 255 DB SectionStraight & 255 DB SectionBar & 255 DB SectionDown2 & 255, SectionFel & 255 DB SectionStraight & 255 ;DB Stop ; ; ########################################################################## ; ; --- actual road drawing data ; $00 = next byte set color ; > $90 = repeat "block" (byte And 0F) times ; > $80 = repeat "space" (byte And 0F) times ; rest = actual character to be drawn ; Road8 ; yellow block DB $00,$77,$83,$00,$35,$82,$95,$85 Road8b ; "b" DB $00,$77,$20,$02,$20,$00,$35,$82,$95,$85 Road8a ; "a" DB $00,$77,$20,$01,$20,$00,$35,$82,$95,$85 Road8r ; "r" DB $00,$77,$20,$12,$20,$00,$35,$82,$95 ;$85 ; Narrow ; narrow DB $85,$95 ;,$85 ; Buildng ; red block at bottom DB $85,$95,$81,$00,$22,$83,$00,$35,$81 ; RoadBot DB $8A ; $95 RoadC DB $95,$7F,$7F,$7F,$7F,$7F,$95 RoadC1 ; csik DB $00,$21,$9F RoadC2 ; csik DB $00,$36,$9F RoadC3 ; csik DB $00,$46 ;$9F ; ; ; RoadWide DB $9F ; Corner1 DB $89,$E9,$95 Corner2 DB $E9,$9E ; Road5 DB $84,$DF,$95,$69 ;$84 Road2a DB $84,$E9,$95,$5F,$84 Road4 DB $83,$DF,$97,$69 ;$83 Road3a DB $83,$E9,$97,$5F,$83 Road3 DB $82,$DF,$99,$69 ;$82 Road4a DB $82,$E9,$99,$5F,$82 Road2 DB $20,$DF,$9B,$69 ;$20 Road5a DB $20,$E9,$9B,$5F,$20 Road6a DB $E9,$9D,$5F Road1 DB $00,$35,$DF,$9D,$69 ; set color ; RoadDn9 DB $20 RoadDn8 DB $20 RoadDn7 DB $20 RoadDn6 DB $20 RoadDn5 DB $20 RoadDn4 DB $20 RoadDn3 DB $20 RoadDn2 DB $20 RoadDn1 DB $20 RoadDn0 DB $DF,$94,$5F RoadUp0 DB $20 RoadUp1 DB $20 RoadUp2 DB $20 RoadUp3 DB $20 RoadUp4 DB $20 RoadUp5 DB $20 RoadUp6 DB $20 RoadUp7 DB $20 RoadUp8 DB $20 RoadUp9 DB $E9,$94,$69 ; DB $20 River2 ;DB $86 DB $20,$20,$20,$20,$20,$20 River4 ;DB $82 DB $20,$20 ; DB $00,$39,$77,$93,$6F,$00,$26,$82 DB $86 ; ; --- some brown circles (trees) ; Trees1 DB $94 Trees3 DB $00,$19,$D1 Trees2 DB $93,$D1,$96,$D1 ;,$93,$91 ; ; --- middle sections (big blocks) ; RoadK1 DB $93 RoadK4 DB $91,$69,$88,$DF,$91 ;,$93 RoadK2 DB $93 RoadK5 DB $91,$8A,$91 ;,$93 RoadK3 DB $93 RoadK6 DB $91,$5F,$88,$E9,$91,$93 ; ; --- river ; River1 DB $96 River3 DB $92,$00,$39,$77,$93,$6F,$00,$26,$92 ; change to blue here!!! DB $96 ;EOF