Last active
February 17, 2025 18:36
-
-
Save aparrish/31b1639e876e162cf24ddcf7bf10a7fb to your computer and use it in GitHub Desktop.
working on a little programming language for the gameboy. this is an early code example (very much subject to change etc etc)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ 10 print implementation in an experimental stack-based language for | |
the gameboy ] | |
!section tenprint rom0 | |
!staticvar @seed wram0 | |
^inchl_entrypoint | |
$ab &seed put | |
jp &tenprint | |
@waitvblank | |
$44 geff | |
144 diff | |
jpnz &waitvblank | |
ret | |
@rand [ from https://foobles.neocities.org/blog/2024-06-06/prng ] | |
&seed get double | |
jpnc :skip_xor | |
$46 xor $ec add | |
jp :done | |
.skip_xor $eb add | |
.done dup &seed put | |
ret | |
@tenprint | |
$00 $40 puff [ turn off lcd so we can access vram ] | |
[ draw / to tile data ] | |
$00 .loop | |
%11 over lshift over double $88 put | |
%10 over lshift over double inc $88 put | |
inc dup $08 diff | |
jpnz :loop | |
drop | |
[ draw \ to tile data ] | |
$00 .loop2 | |
%11000000 over rshift over double $10 add $88 put | |
%10000000 over rshift over double inc $10 add $88 put | |
inc dup $08 diff | |
jpnz :loop2 | |
drop | |
%10010001 $40 puff [ turn the lcd on again ] | |
%11100100 $47 puff [ set palette ] | |
[ populate the tilemap ] | |
.forever | |
#9800 { dup2 #9A40 eq2 blnot } { | |
dup2 $0 { dup 20 lt } { | |
call &waitvblank | |
dup push | |
over2 rotl add21 | |
call &rand %1 and $80 add rotr put | |
pop inc | |
} while | |
drop drop drop | |
$20 add21 | |
} while | |
jp :forever | |
halt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ 10 print implementation in an experimental stack-based language for | |
the gameboy ] | |
!section tenprint rom0 | |
!staticvar @seed wram0 | |
^inchl_entrypoint | |
$ab &seed put12 | |
jp &tenprint | |
@waitvblank | |
$44 geff 144 diff | |
jpnz &waitvblank | |
ret | |
@rand [ adapted from https://foobles.neocities.org/blog/2024-06-06/prng ] | |
&seed get double jpnc :skip_xor | |
$46 xor $ec add jp :done | |
.skip_xor $eb add | |
.done dup &seed put12 | |
ret | |
@tenprint | |
$00 $40 puff [ turn off lcd so we can access vram ] | |
[ draw / to tile data ] | |
$00 .loop | |
%11 over lshift over double $88 put12 | |
%10 over lshift over double inc $88 put12 | |
inc dup $08 diff | |
jpnz :loop | |
drop | |
[ draw \ to tile data ] | |
$00 .loop2 | |
%11000000 over rshift over double $10 add $88 put12 | |
%10000000 over rshift over double inc $10 add $88 put12 | |
inc dup $08 diff | |
jpnz :loop2 | |
drop | |
%10010001 $40 puff [ turn the lcd on again ] | |
%11100100 $47 puff [ set palette ] | |
%00010000 $00 puff [ read buttons ] | |
[ populate the tile map ] | |
.forever #9800 { | |
call &waitvblank | |
[ set palette based on keys ] | |
$00 geff %1 and { %11100100 $47 puff } { %00011011 $47 puff } ifte | |
[ draw a row ] | |
$0 { | |
*add21 call &rand %1 and $80 add waitvram put21 | |
inc dup 20 lt | |
} while drop | |
$20 add21 | |
dup2 #9A40 ne2 | |
} while drop2 jp :forever | |
halt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment