Coder Social home page Coder Social logo

joeldipops / gbz80-pseudoops Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 1.0 84 KB

Set of rgbasm macros and constants to facilitate readability for modern programmers

License: MIT License

Assembly 99.50% Makefile 0.50%
rgbds game-boy gameboy game-boy-development gbz80

gbz80-pseudoops's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

gb-archive

gbz80-pseudoops's Issues

Add some common utils as well. Here's a potential one

SPRITE_SIZE EQU 4

; Don't think this is possible, but worth a shot.
setOAMStage: macro
OAMStage SET \1
endm

;;;
;
; @param \1 Sprite number
; @param \2 X position
; @param \3 Y position
; @param \4 Pointer to image tile
; @param \5 Flags
; @param \6 preserve HL - if 0, HL will be affected, if 1, HL will be unchanged.
;;;
updateSprite: macro
IF (\7 == 1)
push HL
ENDC

ld HL, OAMStage + (\1 * SPRITE_SIZE)
ldi [HL], \2
ldi [HL], \3
ldi [HL], \4
ldi [HL], \5

IF (\6 == 1)
    pop HL
ENDC

endm

updateSprite 3, OAMStage, 32, 32 CursorFrame1, (HAS_PRIORITY | USE_PALETTE_0), 0

ldh never used

Macros loading from memory (addAny, for example) do not use ldh when effective/possible.

Documentation out of date.

Both doc comments and readme.md are missing some instructions or have incorrect cycles/bytes/flags for certain cases.

`orAny [hl], [hl]` has unexpected behavior

This line makes orAny [hl], [hl] only read from memory once, which is not expected behavior.
This could be useful for reading STAT, for example, or acknowledging by polling memory (some mappers, including custom, work this way)

Jump pseudo instructions that describe conditions better?

This is a really interesting project you have, that really adds a lot of convenient value in a really straightforward, un-intrusive way. I think it's pretty common for developers to create macros for things that would make sense to be instructions, but aren't. A library that provides many of them all at once makes a lot of sense.

A collection of like-minded macros I wrote before but haven't gotten around to publishing involved making jumps clearer. They add pseudo-instructions for jr, jp, call, and ret for when the previous operation (a sub or a cp) produced a "less than", "greater than", "less than or equal", "greater than or equal", "equal", or "not equal" condition.

I feel like instructions of that sort might make sense for this library. I've attached my previous code. If you think the idea is appropriate for your library, feel free to use it to any extent you wish, harvesting directly, or just inspiring your own macros developed to your particular style and standard.

I will warn that while I'm pretty sure they work correctly, they are a year or two old, I never used them in a real project, I don't remember how well I tested them, and so any or all of them may well be implemented incorrectly :D

https://gist.github.com/DonaldHays/a2cdddba571a20d73e9b5f6550695cf3

ldAny bugged if params include macro-variables eg. PARAM_1\@

As well as things like HIGH($4321).

I realised that I've over-complicated ldAny by checking for r8, n8 or [HL], and then realising I'd also need to check for LOW(r16), HIGH(r16) and more.

It should be easier to check for any square brackets instead.

There might still be an issue when passing certain strings baked in to macro-vars, but will be a cleaner anyway.

Lack of `jr` macros

jr is used much, much more than jp, yet only jp has macros defined for it.

mult op questionable performance

Try to improve mult op by using example here: http://wikiti.brandonw.net/index.php?title=Z80_Routines:Math:Multiplication

originally here: #8

'Now constant time, and uses less regs'
eg.

;;;
; mult r16, r8
; Multiples an 8-bit number (in LOW(\1)) with H, result in HL
; @param \2 A temporary register. Make SURE it's not one of H, L, HIGH(\1), or LOW(\1).
; @return HL The result
; @return HIGH(\1) 0
; @return \2 0
; @return ZF Set
; @destroy CF
;;;
mult: macro
ld L, 0
ld HIGH(\2), L
ld \2, 7

; Optimized first iteration
sla H
jr NC, .loop\@
ld L, LOW(\2)

.loop@
add HL, HL
jr NC, .noAdd@
add HL, DE
.noAdd
dec \2
jr NZ, .loop@
endm

Use quotes to make nicer macros

After looking at the src for https://github.com/ISSOtm/rgbds-structs I think I've discovered that you can use quotes to test what's passed in eg
IF ("\1" == "A")

This would mean I could make the ops I'd dreamed of such as ld16 BC, HL instead of ld16 B,C, H,L

In fact I could improve my macros so much by cutting out useless cycles depending on the params

eg. ldAny A,A

ldAny: macro
IF ("\2" == "A")
ld [\1], \2
ELSE
ld A, \2
ld [\1], A
ENDC
endm

Really hope it works the way I think...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.