Machine Code Problem

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
MrVertigo
Posts: 106
Joined: Fri May 27, 2022 9:06 pm

Machine Code Problem

Post 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.
User avatar
mrtinb
Posts: 1912
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: Machine Code Problem

Post 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.
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
MrVertigo
Posts: 106
Joined: Fri May 27, 2022 9:06 pm

Re: Machine Code Problem

Post 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.
User avatar
1024MAK
Posts: 5120
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Machine Code Problem

Post 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
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer 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 later in the year.
MrVertigo
Posts: 106
Joined: Fri May 27, 2022 9:06 pm

Re: Machine Code Problem

Post 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.
Spinnetti
Posts: 255
Joined: Sat Sep 12, 2020 11:29 pm

Re: Machine Code Problem

Post 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?
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
dr beep
Posts: 2084
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Machine Code Problem

Post 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.
dr beep
Posts: 2084
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Machine Code Problem

Post by dr beep »

First routine until the space-line

A holds number, HL holds position on screen
19A38E58-B8D2-4B12-85FF-9F993FC524B2.png
MrVertigo
Posts: 106
Joined: Fri May 27, 2022 9:06 pm

Re: Machine Code Problem

Post 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?
Last edited by MrVertigo on Wed Jul 05, 2023 2:12 pm, edited 2 times in total.
User avatar
mrtinb
Posts: 1912
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: Machine Code Problem

Post 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.
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
Post Reply