Machine Code Problem
Machine Code Problem
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.
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
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.
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
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.
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.
- 1024MAK
- Posts: 5189
- Joined: Mon Sep 26, 2011 10:56 am
- Location: Looking forward to summer in Somerset, UK...
Re: Machine Code Problem
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.
Mark
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.
Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Amp
Standby alert
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb
Looking forward to summer being good this year.
ZX81 Chip Pin-outs
ZX81 Video Transistor Amp
Standby alert
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb
Looking forward to summer being good this year.
Re: Machine Code Problem
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.
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
well, you'll need to convert the number from hex to decimal and write a display routine to write the digits out ya?
Zeddy: ZX80, ZX81/ZXpand, TS1000/ZXpand, TS1500/Zxpand+,Printer
Speccy: 48k, +, +2, +3, TS2068, "Bare Metal" Pi, Next KS2, IF1/Microdrives/Vdrive/Light Gun/VGA-Joy
QL: Minerva/QL-VGA/Custom PSU
C5: 24v, LiFE battery, Disc brakes
Speccy: 48k, +, +2, +3, TS2068, "Bare Metal" Pi, Next KS2, IF1/Microdrives/Vdrive/Light Gun/VGA-Joy
QL: Minerva/QL-VGA/Custom PSU
C5: 24v, LiFE battery, Disc brakes
Re: Machine Code Problem
As you write: you use A, so max value is 255?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.
Am I right?
I have a routine for that.
Re: Machine Code Problem
First routine until the space-line
A holds number, HL holds position on screen
A holds number, HL holds position on screen
Re: Machine Code Problem
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?
Last edited by MrVertigo on Wed Jul 05, 2023 2:12 pm, edited 2 times in total.
Re: Machine Code Problem
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.
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.