Skip to content

Comments on source #2

@chickendude

Description

@chickendude

Hey, i'm really excited to see you start doing some Game Boy stuff! I took a quick look through and had a couple comments:


In my opinion, or 0 should be or a, otherwise or 0 is the same size/speedwise as cp 0 just less clear. or a will be a byte/cycle smaller and faster. or a is pretty standard for checking if a equals 0 (like xor a for setting a to 0).

call LoadDemoSelect
ret
.continue
ret

The common convention when calling a function and returning afterwards is to use jp ... directly instead of call ... \ ret. You also have a ret in the .continue, so the first ret is unneeded regardless.

.load_demo
ld a, [bDemoSelectCursor]
cp a, 4
jr z, .demo5
cp a, 3
jr z, .demo4
cp a, 2
jr z, .demo3
cp a, 1
jr z, .demo2
.demo1
call LoadDemo1
ret
.demo2
call LoadDemo2
ret
.demo3
call LoadDemo3
ret
.demo4
call LoadDemo4
ret
.demo5
call LoadDemo5
ret
.return_to_title
call LoadTitle
ret

This might benefit from a jump table, something like:

.load_demo
  ld hl, demoTable
  ld a, [bDemoSelectCursor]
  add a, a ; x2, as each entry is 2 bytes
  ; add hl, a = demoTable + bDemoSelectCursor * 2
  add a, l
  ld l, a
  adc a, h ; a = h + l + carry flag
  sub l ; a = h + carry flag
  ld h, a
  ; Load demo's address into hl and jump to it
  ld a, [hl+]
  ld h, [hl]
  ld l, a
  jp hl
demoTable:
  dw LoadDemo1 ; cursor = 0
  dw LoadDemo2 ; 1
  dw LoadDemo3 ; 2
  dw LoadDemo4 ; 3
  dw LoadDemo5 ; 4

That would let you easily add more entries, you'd just add the label to the demoTable and be good to go. Alternatively, using jp ... instead of call ... \ ret for all of those LoadDemoX calls would save a bit of space and speed as well.

Hope you don't mind, i've been enjoying your videos and was really excited to see you take on the Game Boy!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions