ZaneDubya / YCPU

An imaginary 16-bit cpu, with a complete specification, emulator, assembler, and disassembler, in C#.
24 stars 3 forks source link

Cartridge stores return value in R0, which is used for message acknowledgement #23

Closed ghost closed 3 years ago

ghost commented 3 years ago

According to cartridge.txt, the cartridge puts the return value for messages in R0 register, but from the YCPU spec, R0 is reserved for message acknowledgement (MSG_ACK, MSG_WAIT, MSG_ERROR).

Should the return value be stored in R1 or R2 instead? (In the meantime I'll use R1 in my implementation.)

ghost commented 3 years ago

I've just realized that keyboard also sends return value as response in some handler. It's at least consistent on MSG_ERROR. Perhaps I could do the same with cartridge, but it feels weird returning 1 on error, which is MSG_ACK and kind of indicate success.

ZaneDubya commented 3 years ago

@Naryosha Would you like to propose a change to the hardware spec, or are you comfortable leaving as is?

ghost commented 3 years ago

Since mentioning that R0 could be something else rather than MSG_* would simply fix the issue, for now I'm comfortable as it is. I'll mention it in my own docs though because it's still an unofficial decision.

I see there are two ways to properly resolve this:

  1. change YCPU specs (mainly section about HWQ $02) to match hardware specs: as written above. Hardware may write to R0, R1, and R2 with anything as defined in their specs.
  2. change hardware specs to match YCPU specs: Hardware may only return MSG_* in R0. It also may not modify R1 and R2 if MSG_ERROR is sent via R0.

If I were to resolve it, it'd take some time. 😅