Monday, May 4, 2020

PEEKPOKE.I

[Table of Contents]
PEEKPOKE.ATR Disk Image

Here is a PEEKPOKE.I include file that you can use in your programs. The POKE procedure and the PEEK function come from the Kyan Pascal 2.x User's Manual for the Atari 8-bit.

  • Procedure POKE(Address, Value)
  • Function PEEK(Address)

Kyan Pascal 2.x only supports up to a two-byte signed integers (-32,768 to 32,767). If the address that you want to peek or poke lies out side that range, you will need to use a Two’s Complement conversion to reach that address. For example, the address 57344:

  • Take the number: 57344
  • Convert the Decimal to Binary: 1110000000000000
  • Moving from RIGHT to LEFT, flip every bit AFTER the first 1: 0010000000000000
  • Convert the Binary to Decimal: 8192
  • Use the negated value: -8192

Source Code


(* PEEKPOKE.I *)
(* Kyan Pascal / Atari 8-bit *)

PROCEDURE Poke(Loc, Val: Integer);

Begin
#a
   LDY #7       ; Offset from _SP to Loc;
   LDA (_SP),Y  ; Get LSB of Loc;
   STA _T       ; Save LSB of loc;
   INY
   LDA (_SP),Y  ; Get MSB of Loc;
   STA _T+1     ; Save MSB of Loc;
   LDY #5       ; Offset from _SP to Val;
   LDA (_SP),Y  ; Load Val into Accumulator;
   LDY #0       ; Clear Y register;
   STA (_T),Y   ; Store the value in the accumulator
                ; in memory location _T;
#
End;

Function Peek(Loc: Integer) : Integer;
Begin
   Peek := 0;

#a
   LDY #7       ; Offset to Loc;
   LDA (_SP),Y  ; Get LSB of Loc;
   STA _T       ; Save LSB of Loc in workspace;
   INY
   LDA (_SP),Y  ; Get MSB of Loc;
   STA _T+1;    ; Save MSB of Loc in workspace;
   LDY #0;      ; Clear Y register;
   LDA (_T),Y   ; Load accumulator with the
                ; Address being Peeked;
   LDY #5       ; Offset to Function Identifier
   STA (_SP),Y  ; Store contents of the accumulator
                ; in LSB of Function Identifier
   INY
   LDA #0       ; Load Accumulator with 0 for MSB
                ; of return integer
   STA (_SP),Y  ; Store contents of accumulator;
                ; in MSB of Function Identifer;
#
End;

No comments:

Post a Comment