avatar
L Break Into Program @breakintoprogram.co.uk

Got the line clipping working yesterday evening. I'm working on the principle of writing it quickly first in C, then once I'm happy with the algorithms optimising it in assembler. As mentioned in the commentary, polygon clipping is slightly more complicated, but not much more so.

Video thumbnail
aug 27, 2025, 2:01 pm • 61 4

Replies

avatar
Paul "Paulie" Hughes @pauliehughes.bsky.social

Nice one! I loved hand rolling rasterisers, clippers, 8 bit maths routines. Such a nice time.

aug 27, 2025, 7:07 pm • 2 0 • view
avatar
L Break Into Program @breakintoprogram.co.uk

Yeah, it's all coming back to me, with the adding luxury of 30-odd years experience. I've more or less caught up with where I was back in the day now.

aug 27, 2025, 8:02 pm • 4 0 • view
avatar
Paul "Paulie" Hughes @pauliehughes.bsky.social

It all comes flooding back doesn’t it? It’s so much easier the second time around - experience is a wonderful thing! Looking good!

aug 28, 2025, 6:49 am • 6 0 • view
avatar
bugbear6502.bsky.social @bugbear6502.bsky.social

The one thing you know, when you finish a project, is how you *should* have done it...

aug 28, 2025, 9:50 am • 1 0 • view
avatar
bugbear6502.bsky.social @bugbear6502.bsky.social

Do you write the assembler from scratch, "hand compile" into assembler, or get the C compiler to output assembler and optimise that?

aug 27, 2025, 2:56 pm • 2 0 • view
avatar
L Break Into Program @breakintoprogram.co.uk

I usually write the assembler from scratch, once the basic principles have been proved in C.

aug 27, 2025, 2:57 pm • 4 0 • view
avatar
L Break Into Program @breakintoprogram.co.uk

I'm also very impressed by z88dk - I never thought I'd be happy using a C compiler for Z80. Maybe developing the original Agon MOS changed my opinion. Yes, I know the Agon is running on an eZ80, yet the CPU is only slightly more optimised for C.

aug 27, 2025, 8:11 pm • 5 0 • view
avatar
Michael Reed @rhydermike.bsky.social

I wish I'd gone completely over to C programming during the early 16 / 32 bit era. I might have got some finished projects to my name, admittedly at the expense of (quite a lot of) performance.

aug 27, 2025, 10:47 pm • 2 0 • view
avatar
L Break Into Program @breakintoprogram.co.uk

I often hit roadblocks when developing assembly language code trying to optimising it as I go. C breaks that habit. I just write working code, optimise it, then fine tune in assembler.

aug 27, 2025, 10:52 pm • 2 0 • view
avatar
bugbear6502.bsky.social @bugbear6502.bsky.social

I consciously summarized that (even if only working in 'C') as: "It's easier to make working code fast than to make fast code work"

aug 28, 2025, 9:49 am • 2 0 • view
avatar
L Break Into Program @breakintoprogram.co.uk

I only really started using C whilst developing on the first PlayStation. We also had Borland C for PC so it kind of made sense to write our tooling in C too.

aug 27, 2025, 10:49 pm • 1 0 • view
avatar
L Break Into Program @breakintoprogram.co.uk

Righto, all the tricky bits in the clipping routine are now in Z80 assembler. The only thing left is the loop and some conditional branching. Should be easy converting that to Z80. Must admit this workflow of write it quick, optimise later is working really well. It's how I coded on the Playstation.

Video thumbnail
aug 27, 2025, 8:07 pm • 5 0 • view
avatar
Konix Multisystem @konix.bsky.social

Please Sir, Can we haveca konix demo
aug 27, 2025, 8:16 pm • 3 0 • view
avatar
L Break Into Program @breakintoprogram.co.uk

The Cohen-Sutherland clipping algorithm uses a function to quickly determine if a line can be drawn as-is, can be ignored, and if it needs to be clipped, the point of interest. This is it in C, compared to the rewrite in Z80. It should run quicker.

Code snippet in C: // Line clipping // uint8_t xclipRegion(Point16 * p) { uint8_t code = 0; if(p->y < 0) { // top code |= 1; } else if(p->y > 191) { // bottom code |= 2; } if(p->x > 255) { // right code |= 4; } else if(p->x < 0) { code |= 8; // left } return code; } Code snippet in Z80 assembler: ; extern uint8_t clipRegion(Point16 * p) __z88dk_callee ; PUBLIC _clipRegion, clipRegion _clipRegion: POP BC POP IY ; Pointer to the coordinates PUSH BC ; clipRegion: LD L, 0 ; The return value LD A,(IY+3) ; A: p.y (MSB) RLC A ; Don't use RLCA as that doesn't set the Z flag JR C, clipRegionT ; Off top of the screen JR NZ, clipRegionB ; Off bottom of screen LD A,(IY+2) ; A: p.y (LSB) CP 192 JR C, clipRegionH ; We're in the top 192 lines of the screen, so skip clipRegionB: SET 1,L ; Bottom JR clipRegionH clipRegionT: SET 0,L ; Top ; clipRegionH: LD A,(IY+1) ; A: p.x (MSB) RLC A ; Don't use RLCA as that doesn't set the Z flag RET Z ; We're on screen, so ignore JR C, clipRegionL ; We're off the left of the screen, so skip to that SET 2,L ; Right RET clipRegionL: SET 3,L ; Left RET
aug 27, 2025, 4:26 pm • 11 0 • view
avatar
Matt Godbolt @matt.godbolt.org

I didn't know it had a posh name. We always called it "outcoding"

aug 27, 2025, 4:44 pm • 3 0 • view
avatar
L Break Into Program @breakintoprogram.co.uk

I may have picked up that terminology from this book.

aug 27, 2025, 5:08 pm • 3 0 • view
avatar
Matt Godbolt @matt.godbolt.org

That book lived on my desk...I guess I hadn't ever put two and two together. (It also started a lifelong fascination with Vermeer)

aug 27, 2025, 6:11 pm • 2 0 • view
avatar
L Break Into Program @breakintoprogram.co.uk

My code clearly has ideas above its station.

aug 27, 2025, 4:54 pm • 1 0 • view
avatar
Matt Godbolt @matt.godbolt.org

Oh lol not at all! Any amount of junk learned by word of mouth at Argonaut in 1996 is probably not canonical hahah

aug 27, 2025, 5:29 pm • 1 0 • view
avatar
L Break Into Program @breakintoprogram.co.uk

Hahaha! I think Argonaut have earned their 3D stripes, so they can pretty much call it what they want.

aug 27, 2025, 5:56 pm • 0 0 • view
avatar
Matt Godbolt @matt.godbolt.org

I guess? Lol. I learned from some super smart people anyway. Lucky me 😊

aug 27, 2025, 6:10 pm • 1 0 • view
avatar
nivrig.bsky.social @nivrig.bsky.social

That’s cool! I never did any 3D stuff at all, never mind on 8-bit. Is that running on a Next at 3.5Mhz?

aug 28, 2025, 7:34 am • 1 0 • view
avatar
L Break Into Program @breakintoprogram.co.uk

No it’s running flat out. 28Mhz? There’s plenty of scope for increasing the speed yet. The trig functions for example.

aug 28, 2025, 7:37 am • 0 0 • view
avatar
nivrig.bsky.social @nivrig.bsky.social

Well if you ever release the C or asm it'd be interesting to poke at.

aug 28, 2025, 8:20 am • 1 0 • view
avatar
L Break Into Program @breakintoprogram.co.uk

I'll have to see what I can do. I was only really intending on using the C as a scratchpad as I moved it all to assembler. It will probably still be a library that's callable from C.

aug 28, 2025, 9:07 am • 0 0 • view
avatar
nivrig.bsky.social @nivrig.bsky.social

heh, NP. Maybe I should just do my own, for make great learnings :)

aug 28, 2025, 10:14 am • 1 0 • view
avatar
Ade "Theic" 🧐 @stressedlocal.bsky.social

Noice 😎👍🏻

aug 27, 2025, 4:26 pm • 1 0 • view
avatar
Shane McKee @shaneir.bsky.social

While there, what about Elite natively compiled for the Psion 3a...? 😉

aug 27, 2025, 2:08 pm • 1 0 • view