CPC Basic

Would you like to react to this message? Create an account in a few clicks or log in to continue.
CPC Basic

Basic cross-compiler for Amstad CPC


    Get The Cash Game

    Out Bush
    Out Bush


    Posts : 11
    Join date : 2019-12-02

    Get The Cash Game Empty Get The Cash Game

    Post  Out Bush Sat Dec 07, 2019 8:22 pm

    Back in 2016 I started coding this game with CPC BASIC 3 and while I got so far into it, some bits of it appeared on CPC-Rulez and CPC-Power, but I ran into problems when I was trying to Move the Graphics down the Screen with CPC BASIC 3, which ended up in a game being completed in Hisoft Pascal.

    I decided to go back to what I coded in 2016 and see if I could have the graphics moving down the screen. Earlier on I was using a whole heap of User Defined Graphics to make my Graphics look like Sprites along with some Assembly, but in this post I have replaced that with the Simple Sprite Driver I created with CPC BASIC 3.

    The final result is a working game, though shortly I shall be posting a CPC BASIC 3 version of the same game using an Assembly Sprite Driver I created. The advantage with this one though is I can simply tell CPC BASIC 3 to Run in the Emulator and it'll do that.

    Code:

    100 ' Get the Cash! :)
    110 '
    120 ' Use Left / Right Arrow to Get the Cash, but avoid the Obstacles
    130 '
    140 DEFWORD o, x, y, w, z : DIM objects(30)
    150 RANDOMIZE TIME
    155 MODE 0 : BORDER 0 : INK 1,26 : INK 2,13 : INK 3,25 : INK 4,2 : INK 5,11 : INK 6,6
    156 GOSUB 1910
    160 yaxis = 0
    170 FOR setobj=1 TO 30 STEP 3
    180  x1 = setobj + 1
    190  y1 = setobj + 2
    200  GOSUB 540
    210  objects(y1) = yaxis
    220  yaxis = yaxis + &A0
    230  obj = RND MOD 3+1
    240  IF (obj=1 OR obj=2) THEN objects(setobj)=1 ELSE objects(setobj)=3
    245  IF objects(setobj)=3 THEN p = 33 ELSE p = 1
    250  w = objects(x1) : z = objects(y1) : GOSUB 1050
    260 NEXT setobj
    290 xp=20 : yp=1840 : w=xp : z=yp : p=65 : exit = 0 : sc = 0 : GOSUB 1050
    300 FOR ys=1 TO 25 : LOCATE 13,ys : PRINT CHR$(219);: NEXT ys
    310 LOCATE 14,1 : PRINT"Score:"
    320 LOCATE 14,2 : PRINT Sc
    330 WHILE exit = 0
    331  IF INKEY(1)=0 THEN IF xp < 44 THEN p = 97 : w = xp : z = yp : GOSUB 1050 : xp = xp + 4 : p = 65 : w = xp : z = yp : GOSUB 1050 : CALL &BD19
    332  IF INKEY(8)=0 THEN IF xp > 0 THEN p = 97 : w = xp : z = yp : GOSUB 1050 : xp = xp - 4 : p=65 : w = xp : z = yp : GOSUB 1050 : CALL &BD19
    340  FOR ps=1 TO 30 STEP 3
    350  x1 = ps + 1 : y1 = ps + 2
    360  IF objects(y1)<1840 THEN GOSUB 600 : objects(y1) = objects(y1) + &50 ELSE GOSUB 600 : GOSUB 540 : objects(y1) = 0 : objects(ps) = RND MOD 3+1
    365  p=65 : w = xp : z = yp : GOSUB 1050
    370  IF objects(ps)=1 OR objects(ps)=2 THEN p=1 : w = objects(x1) : z = objects(y1) : GOSUB 1050 ELSE p=33 : w = objects(x1) : z = objects(y1) : GOSUB 1050
    385  IF objects(y1)=1840 THEN IF xp = objects(x1) AND objects(ps) = 3 THEN p = 65 : w = xp : z = yp : GOSUB 1050 : sc=sc+10 : LOCATE 14,2 : PRINT sc;
    386  IF objects(y1)=1840 THEN IF xp = objects(x1) AND objects(ps) <> 3 THEN exit = 1
    390  NEXT ps
    450 WEND
    460 CLS : LOCATE 7,8 : PRINT "FINAL" : LOCATE 7,9 : PRINT "SCORE" : LOCATE 8,10 : PRINT sc
    470 LOCATE 8,12 : PRINT "PLAY" : LOCATE 7,13 : PRINT "AGAIN" : LOCATE 7,14 : PRINT "(Y/N)" : WHILE INKEY$<>"" : WEND
    480 WHILE INKEY(46)=-1
    490 IF INKEY(43)<>-1 THEN GOTO 155
    500 WEND
    510 WHILE INKEY$<>"" : WEND : CALL &BC02 : MODE 2 : END
    520 SOUND 135,0,0,0,2,,1 : RETURN
    530 ' pick random number divisible by 4
    540 objects(x1) = RND MOD 48
    550 WHILE objects(x1) MOD 4 <> 0
    560  objects(x1) = RND MOD 48
    570 WEND
    580 RETURN
    590 ' Clear Graphics
    600 p=97
    610 w=objects(x1)
    620 z=objects(y1)
    630 GOSUB 1050
    640 RETURN
    1000 ' 8x8 Sprite Driver
    1010 ' Entry :-
    1020 '  w = x Coordinate
    1030 '  z = y Coordinate
    1040 '  p = Sprite Position (1 = Hazard, 33 = Money Bag, 65 = Bat, 97 = Blank)
    1050 FOR y=z+0 TO z+&3800 STEP &800
    1060  FOR x=w+0 TO w+3
    1070    POKE &C000+x+y,b(p)
    1080    p=p+1
    1090  NEXT x
    1100 NEXT y
    1110 RETURN
    1900 ' Setup Graphics
    1910 DIM b(128):RESTORE 2010
    1920 FOR p=1 TO 128
    1930  READ b(p)
    1940 NEXT p
    1950 RETURN
    2000 ' Hazard
    2010 DATA 0,0,0,0
    2020 DATA 64,128,192,128
    2030 DATA 0,12,4,12
    2040 DATA 64,128,192,128
    2050 DATA 0,12,4,12
    2060 DATA 64,128,192,128
    2070 DATA 0,12,4,12
    2080 DATA 0,0,0,0
    2090 ' Money Bag
    2100 DATA 136,0,0,68
    2110 DATA 100,204,204,152
    2120 DATA 112,224,192,176
    2130 DATA 112,224,240,176
    2140 DATA 112,192,208,176
    2150 DATA 112,224,240,176
    2160 DATA 112,192,192,176
    2170 DATA 16,48,48,32
    2180 ' Bat
    2190 DATA 0,0,0,0
    2200 DATA 0,0,0,0
    2210 DATA 0,0,0,0
    2220 DATA 0,0,0,0
    2230 DATA 128,0,0,64
    2240 DATA 40,0,0,20
    2250 DATA 104,192,192,148
    2260 DATA 60,60,60,60
    2270 ' Blank
    2280 DATA 0,0,0,0
    2290 DATA 0,0,0,0
    2300 DATA 0,0,0,0
    2310 DATA 0,0,0,0
    2320 DATA 0,0,0,0
    2330 DATA 0,0,0,0
    2340 DATA 0,0,0,0
    2350 DATA 0,0,0,0
    Out Bush
    Out Bush


    Posts : 11
    Join date : 2019-12-02

    Get The Cash Game Empty Re: Get The Cash Game

    Post  Out Bush Sat Dec 07, 2019 8:34 pm

    As I mentioned earlier, I also made a second version using an Assembly Sprite Driver, to create this version, the CPC BASIC needs to be Compiled to a DSK image. For the Assembly part I wrote it in the Winape Assembler, the code can be Compiled and saved along with the the "output.bin" file CPC BASIC 3 produced and a small loader needs to be included along the lines of :

    Code:

    10 MEMORY &3FFF
    20 LOAD"SPRDRV.BIN",&A000
    30 LOAD"OUTPUT.BIN",&4000
    40 CALL &4000

    Unfortunately I am unable to attached a DSK image of the game Sad

    But here's the rest of the code:

    Code:

    100 ' Get the Cash! :)
    110 '
    120 ' Use Left / Right Arrow to Get the Cash, but avoid the Obstacles
    130 '
    140 DEFWORD o, x, y, w, z : DIM objects(30)
    150 RANDOMIZE TIME
    160 MODE 0 : BORDER 0 : INK 1,26 : INK 2,13 : INK 3,25 : INK 4,2 : INK 5,11 : INK 6,6
    170 yaxis = 0
    180 FOR setobj=1 TO 30 STEP 3
    190  x1 = setobj + 1
    200  y1 = setobj + 2
    210  GOSUB 540
    220  objects(y1) = yaxis
    230  yaxis = yaxis + &A0
    240  obj = RND MOD 3+1
    250  IF (obj=1 OR obj=2) THEN objects(setobj)=1 ELSE objects(setobj)=3
    260  IF objects(setobj)=3 THEN p = &A04A ELSE p = &A02A
    270  CALL &A000,p,(&C000+objects(y1))+objects(x1)
    280 NEXT setobj
    290 xp=20 : yp=1840 : exit = 0 : sc = 0 : CALL &A000,&A06A,(&C000+yp)+xp
    300 FOR ys=1 TO 25 : LOCATE 13,ys : PRINT CHR$(219);: NEXT ys
    310 LOCATE 14,1 : PRINT"Score:"
    320 LOCATE 14,2 : PRINT Sc
    330 WHILE exit = 0
    340  IF INKEY(1)=0 THEN IF xp < 44 THEN CALL &A000,&A08A,(&C000+yp)+xp : xp = xp + 4 : CALL &A000,&A06A,(&C000+yp)+xp : CALL &BD19
    350  IF INKEY(8)=0 THEN IF xp > 0 THEN CALL &A000,&A08A,(&C000+yp)+xp : xp = xp - 4 : CALL &A000,&A06A,(&C000+yp)+xp : CALL &BD19
    360  FOR ps=1 TO 30 STEP 3
    370  x1 = ps + 1 : y1 = ps + 2
    380  IF objects(y1)<1840 THEN GOSUB 600 : objects(y1) = objects(y1) + &50 ELSE GOSUB 600 : GOSUB 540 : objects(y1) = 0 : objects(ps) = RND MOD 3+1
    390  CALL &A000,&A06A,(&C000+yp)+xp
    400  IF objects(ps)=1 OR objects(ps)=2 THEN CALL &A000,&A02A,(&C000+objects(y1))+objects(x1) ELSE CALL &A000,&A04A,(&C000+objects(y1))+objects(x1)
    410  IF objects(y1)=1840 THEN IF xp = objects(x1) AND objects(ps) = 3 THEN CALL &A000,&A06A,(&C000+yp)+xp : sc=sc+10 : LOCATE 14,2 : PRINT sc;
    420  IF objects(y1)=1840 THEN IF xp = objects(x1) AND objects(ps) <> 3 THEN exit = 1
    430  NEXT ps
    450 WEND
    460 CLS : LOCATE 7,8 : PRINT "FINAL" : LOCATE 7,9 : PRINT "SCORE" : LOCATE 8,10 : PRINT sc
    470 LOCATE 8,12 : PRINT "PLAY" : LOCATE 7,13 : PRINT "AGAIN" : LOCATE 7,14 : PRINT "(Y/N)" : WHILE INKEY$<>"" : WEND
    480 WHILE INKEY(46)=-1
    490 IF INKEY(43)<>-1 THEN GOTO 160
    500 WEND
    510 WHILE INKEY$<>"" : WEND : CALL &BC02 : MODE 2 : END
    520 SOUND 135,0,0,0,2,,1 : RETURN
    530 ' pick random number divisible by 4
    540 objects(x1) = RND MOD 48
    550 WHILE objects(x1) MOD 4 <> 0
    560  objects(x1) = RND MOD 48
    570 WEND
    580 RETURN
    590 ' Clear Graphics
    600 CALL &A000,&A08A,(&C000+objects(y1))+objects(x1)
    620 RETURN

    And the Assembly...

    Code:

       org &a000

       ;; Used in revised Get the Cash game with CPC BASIC 3

       ld l,(ix+&02)
       ld h,(ix+&03)      ;; sprite address
       ex hl,de
       ld l,(ix+&00)
       ld h,(ix+&01)      ;; screen address
       ld (scradr),hl
       ld b,8      ;; row
    .rloop
       push bc
       ld b,4      ;; column
    .ploop
       ld a,(de)
       ld (hl),a
       inc de
       inc hl
       djnz ploop
       
       ld hl,(scradr)
       call &bc26
       ld (scradr),hl

       pop bc
       djnz rloop

       ret

    .scradr
       defw &c000

    .hazard   
       defb 0,0,0,0
       defb 64,128,192,128
       defb 0,12,4,12
       defb 64,128,192,128
       defb 0,12,4,12
       defb 64,128,192,128
       defb 0,12,4,12
       defb 0,0,0,0

    .MonBag
       defb 136,0,0,68
       defb 100,204,204,152
       defb 112,224,192,176
       defb 112,224,240,176
       defb 112,192,208,176
       defb 112,224,240,176
       defb 112,192,192,176
       defb 16,48,48,32

    .Bat
       defb 0,0,0,0
       defb 0,0,0,0
       defb 0,0,0,0
       defb 0,0,0,0
       defb 128,0,0,64
       defb 40,0,0,20
       defb 104,192,192,148
       defb 60,60,60,60

    .Blank
       defb 0,0,0,0
       defb 0,0,0,0
       defb 0,0,0,0
       defb 0,0,0,0
       defb 0,0,0,0
       defb 0,0,0,0
       defb 0,0,0,0
       defb 0,0,0,0
    .end

      Current date/time is Thu Nov 21, 2024 9:40 pm