avatar
L Break Into Program @breakintoprogram.co.uk

Getting used to stack frames in z88dk this morning. I wanted to pass and return a struct (Point8 - 3 bytes). It kind of makes sense in a weird 'let's get C running on a Z80' kind of way.

Code snippet: ; extern Point8_3D rotateX(Point8_3D p, uint8_t a) __z88dk_callee; ; PUBLIC _rotateX _rotateX: POP IY ; Return function address POP HL ; Return data address POP BC ; C: p.x, B: p.y POP DE ; E: p.z, D: a PUSH HL ; Stack the return data address ; ; do something here ; POP HL ; The return data address LD (HL),0x44 ; X INC HL LD (HL),0x55 ; Y INC HL LD (HL),0x66 ; Z PUSH IY ; Restore stack RET
sep 1, 2025, 11:40 am • 27 0

Replies

avatar
L Break Into Program @breakintoprogram.co.uk

Plus I've just fixed Mrs B's laminator by giving it a hard stare.

sep 1, 2025, 8:40 pm • 8 0 • view
avatar
bugbear6502.bsky.social @bugbear6502.bsky.social

Points deducted for incorrect "hard stare" Correct one follows:

image
sep 2, 2025, 7:59 am • 1 0 • view
avatar
Robert @flatduckrecords.co.uk

Watch out!

For sale: A3 Laminator. £50. Slightly used.
sep 1, 2025, 10:08 pm • 2 0 • view
avatar
L Break Into Program @breakintoprogram.co.uk

Hahaha!

sep 1, 2025, 10:14 pm • 0 0 • view
avatar
Code Ninja @iamcodeninja.bsky.social

🎶you're the trouble starter... fixed a laminator...🎶

sep 1, 2025, 8:43 pm • 1 0 • view
avatar
L Break Into Program @breakintoprogram.co.uk

Hahaha!

sep 1, 2025, 8:44 pm • 1 0 • view
avatar
Matthew @ythos.bsky.social

The problem is they know they're the best of stationery equipment, and they can be right prima donnas.

sep 1, 2025, 8:43 pm • 1 0 • view
avatar
L Break Into Program @breakintoprogram.co.uk

I do really like this approach. Figuring out how the code should work in a high level language then optimising the bits that need speeding up works well with my brain. Occasionally in assembler I get stuck in the minutiae. That's the ex-8-bit games programmer in me I suppose.

sep 1, 2025, 8:34 pm • 3 0 • view
avatar
ModalModule 🎵➡️🕹️Comms *open* @modalmodule.bsky.social

I wonder if I could somehow use this same workflow with gbdk2020 c and asm for our gb game. For the most part I can see what the equivalent asm would be, I guess my only issue is knowing the difference in efficiency, especially after the compilation/assembly phase has already optimized it. 🤔

sep 1, 2025, 9:18 pm • 1 0 • view
avatar
L Break Into Program @breakintoprogram.co.uk

Are you writing it mostly in C at the moment? There are obvious things I'm optimising in asm, like the line draw and using trig lookups. This is quite maths heavy, so coding in a high level language first does make a lot of sense.

sep 1, 2025, 9:41 pm • 1 0 • view
avatar
ModalModule 🎵➡️🕹️Comms *open* @modalmodule.bsky.social

It's c, but it's heavily relying on the library of functions that comes with gbdk itself, which I imagine are decently optimized already? 🤷‍♂️

sep 1, 2025, 9:43 pm • 1 0 • view
avatar
L Break Into Program @breakintoprogram.co.uk

Yeah, I would assume so. That's what I'm trying to write at the moment, the optimised library, not so much a game yet. Out of curiosity, does it work on the original Gameboy?

sep 1, 2025, 9:46 pm • 1 0 • view
avatar
ModalModule 🎵➡️🕹️Comms *open* @modalmodule.bsky.social

My game is beyond the CPU speed of the DMG, I had to bump to "2x mode" of CGB (game boy color), but we already planned to use all the color capabilities anyway. Gbdk can build for DMG though, as well as nes and master system.

sep 1, 2025, 9:51 pm • 1 0 • view
avatar
L Break Into Program @breakintoprogram.co.uk

Incredible! I know from experience how limited the CPU is on the DMG compared to a stock Z80.

sep 1, 2025, 9:53 pm • 1 0 • view
avatar
ModalModule 🎵➡️🕹️Comms *open* @modalmodule.bsky.social

Interesting. I guess it makes sense when you compare nes and game boy games, but I hadn't considered the "flavor" of z80 to be a factor (was more thinking about the screen limits etc), but it makes sense for it to also be power efficient.

sep 2, 2025, 1:15 am • 1 0 • view
avatar
L Break Into Program @breakintoprogram.co.uk

Yeah, the Sharp CPU in the original is more like an 8080 than a Z80 so doesn’t have the index registers IX and IY or the alternate register set. Less suited for C than the Z80. But they’ve done it, and also the 6502, which is even less suited IMHO.

sep 2, 2025, 7:57 am • 1 0 • view
avatar
L Break Into Program @breakintoprogram.co.uk

And the corresponding C code now to rotate a point around 3 axis is much tighter. This in turn will be optimised into a single asm function at some point when I can be bothered.

Code snippet Point8_3D rotate3D(Point8_3D * p, Angle_3D * theta) { Point8_3D r1 = rotateX(*p, theta->x); Point8_3D r2 = rotateY(r1, theta->y); Point8_3D r3 = rotateZ(r2, theta->z); return r3; }
sep 1, 2025, 8:32 pm • 0 0 • view
avatar
L Break Into Program @breakintoprogram.co.uk

Busy day being dad's taxi, dropping youngest off at a camp down Wrexham way. Then food and gym. Though this morning I did optimise the 3D rotation stuff so that it is now mostly in assembler. It's so much smaller and neater than the C generated code...

Code Snippet: ; extern Point8_3D rotateX(Point8_3D p, uint8_t a) __z88dk_callee; ; This is an optimised version of this C routine ; ; Point8_3D r = { ; p.x, ; fastCos(p.y, a) - fastSin(p.z, a), ; fastSin(p.y, a) + fastCos(p.z, a), ; }; ; return r; ; PUBLIC _rotateX _rotateX: POP HL ; Pop the return address POP IY ; Return data address POP BC ; C: p.x, B: p.y POP DE ; E: p.z, D: a PUSH HL ; Stack the return address LD (IY+0),C ; Set p.x ; LD B,B ; B: p.y LD C,E ; C: p.z CALL fastCMS LD (IY+1),A ; Set p.y CALL fastSPC LD (IY+2),A ; Set p.z RET
sep 1, 2025, 8:29 pm • 1 0 • view