Page 1 of 3

Machine Code Problem

Posted: Tue Jul 04, 2023 9:15 pm
by MrVertigo
I wrote a simple machine code program to display a series of Fibonacci numbers. I poked it into the iOS ZX81, and the numbers are being displayed as their equivalents from the ZX81 character set, rather than decimal numbers.

Is there an easy explanation for why that is happening or would I need to give more detail of my code etc? It doesn’t usually happen with my short machine code routines.

Re: Machine Code Problem

Posted: Tue Jul 04, 2023 9:34 pm
by mrtinb
If you output to the screen via RST $10, you will output the character belonging to the value in register A.

If you want to output a 16-bit number in decimal, the easiest way is to set the BC register, and return to basic, to print it.

I might have misunderstod you completely.
  • Please come with an example of your code.
  • What it is currently outputting.
  • What you want or expect it to output.

Re: Machine Code Problem

Posted: Tue Jul 04, 2023 10:35 pm
by MrVertigo
I’m printing to the screen by loading the contents of A into the address HL is pointing to. HL is pointing to the display file address, plus 1.

So basically I load A with zero. Load D with zero. Load E with 1. Add E to A. Load E with A. Add D to A. Load D with A. I’ve got that on a loop, printing A each time A changes, by loading A into the address HL is pointing to, incrementing HL each time by one.

I expect a string of decimals on the screen, but I get a string of graphics mostly. Small square for one etc. It’s a Fibonacci sequence if I translate it using the character code list in the manual.

Re: Machine Code Problem

Posted: Tue Jul 04, 2023 11:20 pm
by 1024MAK
If you POKE the number 1 to the display file, the ZX81 ROM will process this as the character with the character code of 1. This is a graphic character.

Character codes 1 through to 9 are also graphic characters.

To get the number 0 to display, the character code is 0x1C. The number 1 is character code is 0x1D.
BASIC Example
BASIC Example
Mark

Re: Machine Code Problem

Posted: Wed Jul 05, 2023 12:15 am
by MrVertigo
So when I’m doing arithmetic using the accumulator, how do I get the numbers that the accumulator is sending to the display file to appear on the screen as decimal numbers?

Is there a machine code routine that would achieve that? I don’t like calling routines from ROM. I like to know what is actually happening.

Re: Machine Code Problem

Posted: Wed Jul 05, 2023 4:17 am
by Spinnetti
well, you'll need to convert the number from hex to decimal and write a display routine to write the digits out ya?

Re: Machine Code Problem

Posted: Wed Jul 05, 2023 9:32 am
by dr beep
MrVertigo wrote: Wed Jul 05, 2023 12:15 am So when I’m doing arithmetic using the accumulator, how do I get the numbers that the accumulator is sending to the display file to appear on the screen as decimal numbers?

Is there a machine code routine that would achieve that? I don’t like calling routines from ROM. I like to know what is actually happening.
As you write: you use A, so max value is 255?
Am I right?

I have a routine for that.

Re: Machine Code Problem

Posted: Wed Jul 05, 2023 11:45 am
by dr beep
First routine until the space-line

A holds number, HL holds position on screen
19A38E58-B8D2-4B12-85FF-9F993FC524B2.png

Re: Machine Code Problem

Posted: Wed Jul 05, 2023 2:03 pm
by MrVertigo
Brilliant, thanks. Yes, I’m staying below 256. Can you explain to me how this routine makes it happen? Is it the ADD A, 28 line that changes the number into the ZX81 character code for the number?

Re: Machine Code Problem

Posted: Wed Jul 05, 2023 2:10 pm
by mrtinb
It first divides the number by 100. But there is not divide on the Z80 CPU. So it subtracts 100, multiple times, and when there is not more hundreds, it displays the counter, and then displaying the first number (the 100s).

Then it continues to divide by 10, and again that is by subtracting 10s, and count how many times. And then displays the count as the 10s.

Finally it displays the rest which is the 1s.