tricks to simplify coding
When i started with programming in assembler i had very simple approach to do things. Just shifting bytes around, doing simple tests and so...
Later i started thinking about data structures like as 'objects' pointed by index register and subroutines as 'methods' on them. Of course there is nothing like inheritance or encapsulation but such approach still helps to keep me aware of what i'm doing.
Recently, i find myself using another helper like this:
so i can do this in code
i wonder, if you use your own snippets to make coding easier.
Later i started thinking about data structures like as 'objects' pointed by index register and subroutines as 'methods' on them. Of course there is nothing like inheritance or encapsulation but such approach still helps to keep me aware of what i'm doing.
Recently, i find myself using another helper like this:
call_from_table ;HL = table ;A = ITEM add a, a add a, l ld l, a jr nc, call_from_table1 inc h call_from_table1 ld a, (hl) inc hl ld h, (hl) ld (call_from_table2 + 1), hl call_from_table2 jp 0
so i can do this in code
ld a, (ix + FRAC_PEN) ld hl, p2_fracpentab call call_from_table ... p2_fracpentab .WORD pen_0 ;adress of subroutine for pen 0 etc. .WORD pen_1 .WORD pen_2which is actualy switch(var) command, less or more .
i wonder, if you use your own snippets to make coding easier.
Post edited by Fikee on
Comments
PRAT LD A,22 RST 16 LD A,B RST 16 LD A,C RST 16 RETMy call from table used in ZX81EMUL
A holds code 0-255
LD A,(DE) ; DE = Programcounter LD L,A ; to lowbyte LD H,B ; B = constant, start of table highbyte LD H,(HL) ; Fetch Highbyte JP (HL) ; jump to routine by value of AThe jump table is 1K in size, 256 bytes for highbyte, 768 bytes for 256 JP NN instructions starting with 00,03,06,.....,FF,02,05,....,FE,01,...,FDAlso some searchfunctions to find the nth record/textstring/level.
waitkey xor a ld hl,23560 ; last key pressed, filled through IM 1 ld (hl),a ; set to NO VALID KEY wkey or (hl) ; Wait until valid key in (hl) jr z,wkey or 32 ; make it always lowercase (ENTER becomes ;) ret ; A holds value of key pressedhttp://codebase64.org/
:)
I'm from a c64 background , well coding wise. Would like to see a site with parallels that all machine use... e.g. change border / screen colour ... pixel and char shift routinues etc.
Even if you don't want to use a basic compiler, the asm library folder for that has a LOT of assembler routines that you might find useful. (and if anyone knows a way to make them more optimal, I'm sure Boriel would love to hear from you). All the basic operations are laid bare in there - it's the run time library for the compiler, in essence.
Furthermore, we're adding in extra libraries, so the help/tutorial/ideas forum has listings for things like a fast square roots, fast sin (and thus cosine and tangent) functions and so forth.
Pretty much all of the above is likely to be copy-paste useful for an assembly programmer.
I would also recommend "z80 assembly language subroutines" by Leventhal and Saville (1983) as a great source of coding structure concepts.
That code won't work. Here's a fix...
call_from_table1 ld a, (hl) inc hl ld h, (hl) ld l,a ld (call_from_table2 + 1), hl call_from_table2 jp 0Here's a better version...
call_from_table1 ld a, (hl) inc hl ld h, (hl) ld l,a jp (hl)And even better (above code is JUMP from table) :
call_from_table1 ld a, (hl) inc hl ld h, (hl) ld l,a call 111 ; In ROM is this "jp (hl)" So you do CALL (HL)Oh, okay then...
call_from_table1 ld a, (hl) inc hl ld h, (hl) ld l,a push hl retThat's the same as JP (HL).
I use the CALL (HL) to handle the keypresses in a game
where HL points to the routine for up/down/left/right.
WorkSPLoop: ld a,(hl) ; type index (or 0xff = end of vars) add a,a ret c ; can only have 0x7f types! push hl ld de,T_SPData ; temp sprite data store ldi ; TYP ldi ; XNO LO ldi ; XNO HL ldi ; YNO LO ldi ; YNO HI ldi ; GNO ldi ; FLG1 LO ldi ; FLG1 HO ldi ; FLG2 LO ldi ; FLG2 HO add a,SPTypes &0xff ld l,a ld h,SPTypes / 0x100 call JumpHL pop de ld hl,T_SPData ; temp sprite data store ldi ; TYP ldi ; XNO LO ldi ; XNO HL ldi ; YNO LO ldi ; YNO HI ldi ; GNO ldi ; FLG1 LO ldi ; FLG1 HO ldi ; FLG2 LO ldi ; FLG2 HO ex de,hl jr WorkSPLoop JumpHL: ld a,(hl) inc l ld h,(hl) ld l,a jp (hl)thats what happen when coding in night :/ actually, the unnecessary writting was introduced when i changed call to jp. but sure, no excuse for such lame construction. i accept my punishment whatever it is.
That's okay - I'm getting a bit of a pasting myself! LOL!
I'm going to hang up my coding clogs real soon! They are getting smelly!
After it's done its work, it'll leave the address of "hlhere" in HL. I use this in relocatable code so that I can work out addresses of tables and whatnot, often doing a PUSH HL / POP IX combo, to give me a base for indirect addressing. It's worth noting though that when you call code via a USR statement, BC contains the address called, and this can also be useful.
It has a slightly different instruction set.
No 'djnz'. But auto increment/decrement of HL...
Here, look at this (my Mr.do! code)...
http://web.archive.org/web/20070511225944/myweb.tiscali.co.uk/frobush/mrdo.txt
EDIT - stick that up your arse!
EDIT: i wonder which assembler was used to compile it. never seen HEX directive before.
I was using the Ocean assembler - running on an ST, which had loads of made-up opcodes to produce the Z80 Gameboy code. It wasn't very reliable, not what I was used to (the in-house Special FX system), but had to use it because it was a multi-player link-up thing. One ST and two Wideboys. It never worked of course. You would be lucky if the the two GBs kept in sync for a minute.
We all got made redundant anyway before it was finished - the limited release has the two player option removed! (I have a copy- from Germany - R@RE).
If anyone wants it feel free to make an offer. I'll sign it too!
The HEX directive was just that. You used a utility to grab graphics and saved out in various formats. 'HEX' was just save out as hex in source. None of that was typed in!
A great time saver!
Yeah, if you look throught the code you'll see a lot of this!
Always thought this was funny...
I had an early Gameboy to work with. This was priceless! All Gameboy games had to work on this machine no matter what! This was one of the 1st, I don't know, 10,000 units produced - later models were improved - but all games had to work perfectly on one of these!
EDIT - I love waking up to the smell of a burning Gameboy! (We went through about two a week)
Arrghh! The nightmare I had with the GB's link cable!! I reckon I probably spent more time (too much time!) on getting this to work than on any other single part of the game - especially on the bits that mattered! Sadly, it shows! I put it down to the usual movie licence rush-to-finish! That's my excuse, and I'm sticking to it!
Still - at least one reviewer said "The implementation is absolutely flawless" when he wrote about the link cable support... The rest of the review isn't worth mentioning!! :lol::lol::lol:
Come on Chris - what game is this! I need to know!
Haha - I'm not sure I'm brave enough to admit it!! :lol::lol::lol:
Think comic-book movie tie-in, Patrick Stewart, Hugh Jackman... :oops:
The game-play ended up an absolute abortion! The play-testers (read secondary school drop-outs!) had too little time to fine-tune the game before the (movie) release deadline.
Which was a shame really, as all of the parameters within the main engine were tweakable by the testers themselves. So they could have created something that played a damn sight better than the lame effort that eventually hit the shelves!
Still - the graphics looked pretty if nothing else. Oh, and the link worked well. ;)
They make your code less simple, much harder to understand after two weeks. Using various tricks may make your code more efficient but not simpler.
;)
Well, it's obviously X-Men. Did you work for Software Creations at all?
Two weeks? Is that it? Two weeks?
My life.
Two f*cking weeks!
No. The dying embers of Probe - of which a couple of blokes forked-off and formed Crawfish Interactive. The CGB version of XM was done at Crawfish for Activision. I was there until just before their demise. Razorback Developments was born from the death of Crawfish by David Leitch - who worked as a freelancer for Crawfish and (getting it back on Speccy topic!) did some Speccy stuff and is listed on Infoseek HERE.
Just a few days ago I found out the ex-CEO of Crawfish is now an actor!! How people's lives pan out is fascinating! :-o
My graphics on "Spiderman And The Xmen Vs Arcade's Revenge"! That's Gambit. I did Storm too!
EDIT - SNES
It's true what they say you know - the past always catches up and gives you a bloody great bite in the arse! :-P
Yeah, sorry for side tracking you interesting post - it's just that this was work that I did that I haven't seen ever!
Sorry!
Anyway, getting back to Fikee's original post - here's my number one "trick" to simplify coding:
Comment, Comment and Comment again!!
Makes the code a whole lot simpler when you stumble across it again in a few years time! ;);)