HOME

Part 6: Using a W65C02 Simulator:

Check if Key Press Input is Hexadecimal Characters 0-9, A-F, a-f

Overview

Learning 65c02 assembly language is not easy as I am being reminded of once again. I found Z80 coding so much easier. Anyway...

 

When I wrote the hexParser routine (line 356+) of SBC3.0_ACIA-VIA__8j.asm, I did it from scratch because the stuff I found on the web did not seem to make sense. The problem was I did not know how the Carry bit worked with CMP and SBC. So I grabbed a portion of the hexParser routine that starts on line 356 and modified it for 6502 Simulator IDE from Oshonsoft. (Modifying it means replacing display routine "jsr kpWrite" with "sta $7000", and input routine "jsr kpRead" with "lda $7001".)  Attached is the modified code in hexParser that I call testHexIn.asm

When I ran the simulator I changed line 9 from "cmp #$67" to "cmp #$66". With $67 it should error and with $66 it should pass. That's  because $67 is "g", $66 is "f" and "g" is not a hexadecimal number from 0 to 9, A to F, nor a to f.  I also tried using the Peripheral Devices' Input Terminal feature for address $7001 - both work well.

 

To use the sim once you've downloaded it for its limited trial phase:

- click Tools|Assembler

- in Assembler: File|Opem|testHexIn.asm

- in Assembler: Tools|Assemble & Load

- in IDE: Tools|Memory Editor. You should see the  assembled code that is located at $0000

- in IDE: Tools|Memory Editor 2. Use the right-side slider so that 0100 is at the top of the window. Now you can monitor the Stack that starts at $01FF

- in IDE: Tools|Peripheral Devices

- in Peripheral Devices add the following: 

  I/O Port $7000 OUT (This outputs to the terminal.)

  I/O Port $7001 IN (This inputs from the terminal .)

  I/O Port $7002 OUT

  I/O Port $7003 OUT

  Output Terminal I/O Port $7000

  Input Terminal I/O Port $7001

- in IDE: Tools|Watch Variables. Here you can later add named variables of interest

 

When you did Assemble and Load earlier, it created an object file, hex file, etc., that you'll probably want to locate to its own folder because the IUDE will create a number of files when it runs.

 

Go to the IDE, click Rate and ensure Step By Step is chosen.

Under Simulation, click <F1> to Start. The action will be happening initially in the large Assembler window and the register values will change in the IDE window.

Press <F2> under Simulation to advance from instruction to instruction. You must stay in this window for your next press of <F2> to work.

Before you advance to line 9, click Send Hex Bytes in the bottom of the Peripheral Devices and add 67 which will be used in line 9.

When you execute line 11 you should see the letter 'g' appear in the Output Terminal portion of the Peripheral Devices window. Continue thru the program until it fails in line 17. If you hold down <F2> you'll see the fail message quickly appear in the output terminal window.

Within the IDE, press <F3>to stop the simulation.

In the Peripheral Devices window, Clear the Output Terminal.

 

Make Some Changes:

Run the sim again but change the input terminal value to 66.

Within the IDE, File|Clear Memory.

Within the Assembler, Tools|Assemble & Load.
 

Then rerun the sim using <F3> first to stop it, then <F1> followed by <F2> and watch what happens in lines 11 and 40 as register A is pushed onto the stack in Memory Editor 2, then popped off the stack later in line 40.

 

Try the following hex values (the characters are adjacent) to ensure the code works:

$67 g

$66 f

$61 a

$47 G

$46 F

$41 A

$3A :

$39 9

$30 0 

$2F /

$20 <space>

 

User Menu Code

Only 8 of the 20 user menu commands have been implemented so far in SBC3.0_ACIA-VIA__8j.zip

  ? to see the menu

  Q or q to reset the SBC

  C or c to clear the screen

  A or a to see a table of displayable standard and extended ASCII characters (0x20 - 0x7E, 0xB0 - 0xDF)

  K or k to see a single key press display as well as its hex value

  Y or y to see the ASCII hex values of 10 characters you type

  F or F to echo a 4-digit number (needs work)

  H or h parses a key press to see if it is hex character: 0 to 9 or A to F

  Z or z to see a table of zeros when locations $100 to $1FF are "zeroed out". Actually, you would see nothing so I swapped $00 (the ASCII Null character) for $30 which is the ASCII number 0 character

Oshonsoft 6502 Simulator IDE

(Click to Enlarge)

 

 

 

Updated 2023-07-25 @ 8am

 

TOP

 

HOME