peek

чтение байта из памяти

peek (addr) -> val

Параметры:
addr - любой адрес из пространства 64Kb памяти, из которого Вам нужно прочесть значение байта

Возвращает:
val - значение байта по указанному адресу

Описание:
Эта функция позволяет читать значения памяти TIC - байт.
Она удобна для доступа к ресурсам, созданным с помощью интегрированных средств, таких как спрайты, карты, звуки, данные картриджа.
Адрес указывается в шестнадцатеричном формате, но возвращаемое значение в десятичном.

Пример:

Запустить или скачать картридж примера.

-- title:  peek/poke demo
-- author: 
-- desc:   
-- script: lua
-- input:  gamepad

-- use poke to create a sprite from a hexadecimal data string
img="a000000aa0f00f0aaaaaaaaaaafaaa6aafffaaaaaafaa6aaaaaaaaaa33333333"
-- foreach of the 32 bytes in the sprite
for i=0,31 do
  --extract the data from the string 2 chars at time
  s = string.sub(img,i*2+1,i*2+2)
  --convert the hex string to a decimal number
  val = tonumber(s,16)
  --put the value in the RAM area dedicated to sprites, sprite number 4
  poke(0x4000+128+i,val)
end
sync()
-- read back the sprite data and print it to console
msg=''
-- foreach of the 32 bytes in the sprite
for i=0,31 do
  --read the byte value in decimal format
  val=peek(0x4000+128+i)
  -- convert the value in hexadecimal format
  s=string.format("%02x",val)
  -- concatenate the string to a final message
  msg=msg..s
end

-- print it to the console
trace(msg)

function TIC()
  cls()
  print('Done.. have a look at the sprite editor.',0,10) 
  print('And to the console also.',0,20)
end

Запустить или скачать картридж примера.

-- title:  peek/poke demo
-- author: 
-- desc:   
-- script: moon
-- input:  gamepad

-- use poke to create a sprite from a hexadecimal data string
img="a000000aa0f00f0aaaaaaaaaaafaaa6aafffaaaaaafaa6aaaaaaaaaa33333333"
-- foreach of the 32 bytes in the sprite
for i=0,31 
  --extract the data from the string 2 chars at time
  s = string.sub(img,i*2+1,i*2+2)
  --convert the hex string to a decimal number
  val = tonumber(s,16)
  --put the value in the RAM area dedicated to sprites, sprite number 4
  poke(0x4000+128+i,val)
sync()
-- read back the sprite data and print it to console
msg=''
-- foreach of the 32 bytes in the sprite
for i=0,31 
  --read the byte value in decimal format
  val=peek(0x4000+128+i)
  -- convert the value in hexadecimal format
  s=string.format("%02x",val)
  -- concatenate the string to a final message
  msg..=s

-- print it to the console
trace msg

export TIC=->
  cls()
  print 'Done.. have a look at the sprite editor.',0,10
  print 'And to the console also.',0,20
// title: peek/poke demo
// author:
// desc:
// script: js
// input: gamepad

// use poke to create a sprite from a hexadecimal data string
img = "a000000aa0f00f0aaaaaaaaaaafaaa6aafffaaaaaafaa6aaaaaaaaaa33333333"
// foreach of the 32 bytes in the sprite
for (i = 0; i < 32; i++) {
  //extract the data from the string 2 chars at time
  s = img[i * 2 + 1] + img[i * 2]
  //convert the hex string to a decimal number
  val = parseInt(s, 16)
  //put the value in the RAM area dedicated to sprites, sprite number 4
  poke(0x4000 + 128 + i, val)
}
sync()

// read back the sprite data and print it to console
msg = ''
// foreach of the 32 bytes in the sprite
for (i = 0; i < 32; i++) {
  //read the byte value in decimal format
  val = peek(0x4000 + 128 + i)
  // convert the value in hexadecimal format
  s = val.toString(16)
  // concatenate the string to a final message
  msg += s
}

// print it to the console
trace(msg)

function TIC() {
  cls()
  print('Done+ have a look at the sprite editor.', 0, 10)
  print('And to the console also.', 0, 20)
}

results matching ""

    No results matching ""