Code: Select all
type memorycell
as ubyte cell : 1
as ubyte paritycell : 1
as ubyte read_write_state : 1
as ubyte protected_mode : 1
declare function rw_cell (value as ubyte = 0) as ubyte
declare sub lock_cell
declare sub unlock_cell
declare sub write_mode
declare sub read_mode
end type
function memorycell.rw_cell (value as ubyte = 0) as ubyte
' print "RW CELL"
select case read_write_state
case 0
if paritycell <> cell then return cell
case 1
if protected_mode = 0 then
cell = value
paritycell = not value
end if
end select
end function
sub memorycell.lock_cell
' PRINT "LOCKCELL"
protected_mode = 1
end sub
sub memorycell.unlock_cell
' PRINT "UNLOCKCELL"
protected_mode = 0
end sub
sub memorycell.write_mode
' PRINT "WRITEMODE"
read_write_state = 1
end sub
sub memorycell.read_mode
' PRINT "READMODE"
read_write_state = 0
end sub
type mcell_ubyte
dim as memorycell mcell(8)
declare sub convert_ubyte_to_celldata(value as ubyte)
declare function convert_celldata_to_ubyte as ubyte
end type
sub mcell_ubyte.convert_ubyte_to_celldata(value as ubyte)
'PRINT "CONVERTING TO CELLDATA"
for i as integer = 0 to 7
mcell(i).unlock_cell
mcell(i).write_mode
mcell(i).rw_cell bit(value,i)
mcell(i).read_mode
mcell(i).lock_cell
next
end sub
function mcell_ubyte.convert_celldata_to_ubyte as ubyte
'PRINT "CONVERTING TO UBYTE"
dim as ubyte buffer
for i as integer = 0 to 7
if mcell(i).rw_cell = 1 then
buffer = bitset(buffer,i)
else
buffer = bitreset(buffer,i)
end if
next
return buffer
end function
'EXAMPLE STARTS HERE
dim as mcell_ubyte health
health.convert_ubyte_to_celldata 100
locate ,,0
do
locate 1
print "INCRASE/DECRASE HEALTH WITH +/-"
SELECT CASE INKEY
CASE "+"
health.convert_ubyte_to_celldata health.convert_celldata_to_ubyte + 1
case "-"
health.convert_ubyte_to_celldata health.convert_celldata_to_ubyte - 1
case chr(27)
exit do
end select
print "YOUR HEALTH :";health.convert_celldata_to_ubyte; " "
loop