Suggestions on formatting of code
Re: Suggestions on formatting of code
Thank you [mention]Ast A. Moore[/mention],
I currently just use notepad, but use VS Code for other stuff, so will see if that has some of the functionality you mention. VS Code is good because it runs on both Windows and Linux.
I currently just use notepad, but use VS Code for other stuff, so will see if that has some of the functionality you mention. VS Code is good because it runs on both Windows and Linux.
- flatduckrecords
- Manic Miner
- Posts: 787
- Joined: Thu May 07, 2020 11:47 am
- Location: Oban, Scotland
- Contact:
Re: Suggestions on formatting of code
I’ve found that re-indenting unfamiliar code is a useful aid to understanding it. [mention]Alessandro[/mention] shared a really useful text-scrolling routine a while ago, and walking through it a few lines or a block at a time helped me to understand it better. Nothing wrong with the original formatting, I should say! (I’m very new to assembly so still developing my own taste/style anyway) but I found the process of visually marking each line in way that made sense to me (i.e. to distinguish what’s a label, from an opcode, from a reference to a label, etc.) to be a useful exercise.
When writing my own code I use VS Code which auto-indents each new line, as [mention]chilledgamer[/mention] mentioned. Being able to block-edit chunks of code is really helpful too. Plugins are available to help with syntax-highlighting (which I find helpful) and auto-suggest (but that just seems to get in the way as often as it helps!)
When writing my own code I use VS Code which auto-indents each new line, as [mention]chilledgamer[/mention] mentioned. Being able to block-edit chunks of code is really helpful too. Plugins are available to help with syntax-highlighting (which I find helpful) and auto-suggest (but that just seems to get in the way as often as it helps!)
Re: Suggestions on formatting of code
same here! i'm using this method to understand other people's code for decades.flatduckrecords wrote: ↑Thu Jul 02, 2020 8:48 pm I’ve found that re-indenting unfamiliar code is a useful aid to understanding it.
- Turtle_Quality
- Manic Miner
- Posts: 506
- Joined: Fri Dec 07, 2018 10:19 pm
Re: Suggestions on formatting of code
So no-one indenting for loops, conditional code etc ???
Just throwing that in there as that was the norm with VBA code where I worked a few years ago, and kind of helped with visibility. Obviously it was not practical on the Spectrum but now everyone editing code on PCs not a 32 column Spectrum
Just throwing that in there as that was the norm with VBA code where I worked a few years ago, and kind of helped with visibility. Obviously it was not practical on the Spectrum but now everyone editing code on PCs not a 32 column Spectrum
Definition of loop : see loop
Re: Suggestions on formatting of code
it is not even always possible, considering that jumps can create a fine web. it is much easier (and cleaner, i believe) to split the code to "logical blocks" with empty lines.Turtle_Quality wrote: ↑Thu Jul 02, 2020 9:33 pm So no-one indenting for loops, conditional code etc ???
Re: Suggestions on formatting of code
Exactly, it's not always possible/useful to apply best formatting practises from higher level languages to assembly.ketmar wrote: ↑Thu Jul 02, 2020 9:37 pmit is not even always possible, considering that jumps can create a fine web. it is much easier (and cleaner, i believe) to split the code to "logical blocks" with empty lines.Turtle_Quality wrote: ↑Thu Jul 02, 2020 9:33 pm So no-one indenting for loops, conditional code etc ???
I have a habit of always putting an empty line after jp/jr/call/ret. I also agree with ketmar that blank lines are a good way of separating logical blocks of code. Multiple lines and/or decorated comments for larger units, aka
Code: Select all
; --------------------------------------
; A new section starts here
; --------------------------------------
Re: Suggestions on formatting of code
I use VS code with a z80 formatter/highlighter found on marketplace- works great on Mac as well.
https://api.zxinfo.dk/v3/ - ZXDB API for developers
zxinfo-file-browser - Cross platform app to manage your files
https://zxinfo.dk - another ZXDB frontend
zxinfo-file-browser - Cross platform app to manage your files
https://zxinfo.dk - another ZXDB frontend
Re: Suggestions on formatting of code
I always use uppercase for the Z80 instructions. Just seems to make them immediately stand out against the rest of the test. That and it's a habit from the past!
Cosmium
https://cosmium.itch.io/
https://cosmium.itch.io/
- Ast A. Moore
- Rick Dangerous
- Posts: 2641
- Joined: Mon Nov 13, 2017 3:16 pm
Re: Suggestions on formatting of code
To me, lowercasing the instructions has always looked neater. Not as SCREAMY AND SHOUTY as using all uppercase. Oh, and it’s too much extra work to hold down the Shift key.
Every man should plant a tree, build a house, and write a ZX Spectrum game.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
- Einar Saukas
- Bugaboo
- Posts: 3144
- Joined: Wed Nov 15, 2017 2:48 pm
Re: Suggestions on formatting of code
Next time try using CAPS LOCKAst A. Moore wrote: ↑Fri Jul 03, 2020 1:04 amTo me, lowercasing the instructions has always looked neater. Not as SCREAMY AND SHOUTY as using all uppercase. Oh, and it’s too much extra work to hold down the Shift key.
EDIT: Jokes aside, I personally think lowercase mnemonics are more legible too.
- Ast A. Moore
- Rick Dangerous
- Posts: 2641
- Joined: Mon Nov 13, 2017 3:16 pm
Re: Suggestions on formatting of code
Funny you should mention the Caps Lock key. I have it disabled system-wide.Einar Saukas wrote: ↑Fri Jul 03, 2020 1:20 amNext time try using CAPS LOCKAst A. Moore wrote: ↑Fri Jul 03, 2020 1:04 amTo me, lowercasing the instructions has always looked neater. Not as SCREAMY AND SHOUTY as using all uppercase. Oh, and it’s too much extra work to hold down the Shift key.
Every man should plant a tree, build a house, and write a ZX Spectrum game.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Re: Suggestions on formatting of code
What a waste. That key should be remapped as a second Ctrl key, of course
Re: Suggestions on formatting of code
I use CAPS for constant values I've defined at the top of a file. Everything else is lower case.
I sometimes extra-indent loops, or the bits between PUSH and POP of data, to help keep track of it.
I also include a file of macros that defines things like SCREEN EQU 16384, and also JPEQ, JPGE and JPLT to use instead of jp nz, jp nc or jp c following a 'compare' as I can never remember which way round to use the last two. It's then a reminder that there's no way to do JPGT or JPLE with a single operation.
Also define stuff like WAIT_VBL as EI followed by HALT.
I sometimes extra-indent loops, or the bits between PUSH and POP of data, to help keep track of it.
I also include a file of macros that defines things like SCREEN EQU 16384, and also JPEQ, JPGE and JPLT to use instead of jp nz, jp nc or jp c following a 'compare' as I can never remember which way round to use the last two. It's then a reminder that there's no way to do JPGT or JPLE with a single operation.
Also define stuff like WAIT_VBL as EI followed by HALT.
Re: Suggestions on formatting of code
...Isn't that more keystrokes?
My Speccy site: thirdharmoniser.com
- Ast A. Moore
- Rick Dangerous
- Posts: 2641
- Joined: Mon Nov 13, 2017 3:16 pm
Re: Suggestions on formatting of code
I’m in the same club.
Every man should plant a tree, build a house, and write a ZX Spectrum game.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Re: Suggestions on formatting of code
Yes, by one, but it's also an easy way to remember to do an EI before a HALT where your design needs it so you don't deliberately hang your own code.
Re: Suggestions on formatting of code
That's a bit like the perpetually cryptic (to me at least!) RRCA and RRA etc. I can never can remember which one does what with the carry and always have to look it up. Maybe some macros to clearly differentiate these would be helpful to?
Cosmium
https://cosmium.itch.io/
https://cosmium.itch.io/
- Einar Saukas
- Bugaboo
- Posts: 3144
- Joined: Wed Nov 15, 2017 2:48 pm
Re: Suggestions on formatting of code
I could never remember it either, that's one of the reasons I did this:
https://www.ime.usp.br/~einar/z80table/index.html
Click on "MISC" at the bottom of that page.
Re: Suggestions on formatting of code
as we started talking about remembering commands... i'm often looking into Zymosis code to remember details on some instructions. there cannot be a better reference than a working Z80 emulator! ;-)
Re: Suggestions on formatting of code
Good point. I might add RR8 and RR9 to my macros file to remember how many bits are used, as I think RR and RRC are defined the wrong way round.
- Ast A. Moore
- Rick Dangerous
- Posts: 2641
- Joined: Mon Nov 13, 2017 3:16 pm
Re: Suggestions on formatting of code
. . . to say nothing of the logical and arithmetic shifts.
Every man should plant a tree, build a house, and write a ZX Spectrum game.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Re: Suggestions on formatting of code
A round of appreciation for Einar's z80table! Opening that up is pretty much always my first action when doing any serious Z80 coding.
- Ast A. Moore
- Rick Dangerous
- Posts: 2641
- Joined: Mon Nov 13, 2017 3:16 pm
Re: Suggestions on formatting of code
I use a copy an offline copy of this. I made a few corrections to it.
Every man should plant a tree, build a house, and write a ZX Spectrum game.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Re: Suggestions on formatting of code
Nice to see everyone's approach.
I'm putting labels on a separate line to be more flexible with using descriptive names.
I'm putting labels on a separate line to be more flexible with using descriptive names.
Code: Select all
call clearPlayArea
announceLvl2:
xor a
ld (flagSkipSegment),a
Re: Suggestions on formatting of code
XoRRoX wrote: ↑Sun Jul 05, 2020 9:46 pm Nice to see everyone's approach.
I'm putting labels on a separate line to be more flexible with using descriptive names.
Code: Select all
call clearPlayArea announceLvl2: xor a ld (flagSkipSegment),a
...So just out of interest (for someone who doesn't do a lot of 'modern' development), what is it about camel case that you like/prefer?andydansby wrote: ↑Thu Jul 02, 2020 5:57 pm My preference has been for camelCase, just easier on my eyes.
Or is it a habit thing that's been learned (e.g. Javascript)?
My Speccy site: thirdharmoniser.com