Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 02:16 11 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Array of Bytes

Author Message
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1116
Posted: 05:39am 28 Feb 2018
Copy link to clipboard 
Print this post

I am working on an emeulation program for an old 8 bit computer and needed to simulate the memory. I need to read and write 8 bits of data at a time with an indexing pointer (the Program Counter in old 8 bit machines).

I looked at Long Strings but decided I could do it with an integer array and developed the two routines below to simulate reading from and writing to an arbitrary length memory stack from address 0 to whatever maximum is desired within the constraints of the MMs available memory.

I hope this may be of use to anyone doing anything similar.

Doug.

  Quote  
'*******************************************************
' A couple of routines to simulate the getting and putting
' of 8 bits of data from an array of integers to simulate
' the memory of an old 8 bit computer. Bites are addressed
' 0 through to MaxBites.
' The routines use an integer array and require an integer
' of 0 through 255 to be stored or returned
' - no error checking included here.
' The misspelling of Byte to Bite was intentional so as
' not to confuse MMB.

' You should envisage the layout as follows

' Array(0) Bite 7 Bite 6 Bite 5 Bite 4 Bite 3 Bite 2 Bite 1 Bite 0
' Array(1) Bite 15 Bite 14 Bite 13 Bite 12 Bite 11 Bite 10 Bite 9 Bite 8
' Array(2) Bite 23 Bite 22 Bite 21 Bite 20 Bite 19 Bite 18 Bite 17 Bite 16
' .... and so on. Bite 0 being the LSB 8 bits of array(0), Bite 1 the next ...
'*************************************************************

' Global variables required by the two subroutines below
dim BiteCounter
dim MaxBites = 1024
dim BiteArray%(MaxBites \ 8 + 1)
dim Bite%

' Some test code.
' Example that fills the array with random data
for BiteCounter = 0 to MaxBites
local tstval
tstval = fix(rnd * 256)
Bite% = tstval
print "BiteCounter = ",hex$(BiteCounter),"Bite = ",hex$(Bite%)
PutBite BiteArray%(),BiteCounter,Bite%
next

' Example of pulling data from array
for BiteCounter = 0 to MaxBites
GetBite BiteArray%(),BiteCounter
print "BiteCounter = ",hex$(BiteCounter),"Bite = ",hex$(Bite%)
next
end

'*******************************************************************
' These are the two subroutines to do the work
' Put Bite into array
sub PutBite BiteArray%(),BiteCounter,Bite%
local PosMask,BiteArrayIndex,BiteShifted%,xx
PosMask = BiteCounter mod 8 ' which bite in the 64 bit integer?
BiteShifted% = Bite%
for xx = 0 to PosMask ' shift the bite into position in the integer
if xx <> 0 then ' correct for 0 to 0 giving 1 unwanted pass through
BiteShifted% = BiteShifted% << 8
endif
next xx
BiteArrayIndex = BiteCounter \ 8 ' calculate the index into the array
BiteArray%(BiteArrayIndex) = BiteArray%(BiteArrayIndex) or BiteShifted%
End sub

' Get Bite from array - see comments above
sub GetBite (BiteArray%(),BiteCounter)
local PosMask,BiteArrayIndex,BiteShifted%,xx
PosMask = BiteCounter mod 8
BiteShifted% = &HFF
for xx = 0 to PosMask
if xx <> 0 then
BiteShifted% = BiteShifted% << 8
endif
next xx
BiteArrayIndex = BiteCounter \ 8
Bite% = BiteArray%(BiteArrayIndex) AND BiteShifted%
End sub


... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025