CPU-Z80-Disassembler

 view release on metacpan or  search on metacpan

t/data/zx48_base.asm  view on Meta::CPAN


;; K-CH-SET
K_CH_SET:
        ld a,l                  ; make a copy of the low address byte.
        ld hl,0x5C04            ; point to KSTATE-4
                                ; (ld l,$04 would do)
        cp l                    ; have both sets been considered ?
        jr nz,K_ST_LOOP         ; back to K-ST-LOOP to consider this 2nd set

;   now the raw key (0-38d) is converted to a main key (uppercase).

        call K_TEST             ; routine K-TEST to get main key in A

        ret nc                  ; return if just a single shift

        ld hl,0x5C00            ; point to KSTATE-0
        cp (hl)                 ; does the main key code match ?
        jr z,K_REPEAT           ; forward to K-REPEAT if so

;   if not consider the second key map.

        ex de,hl                ; save kstate-0 in de
        ld hl,0x5C04            ; point to KSTATE-4
        cp (hl)                 ; does the main key code match ?
        jr z,K_REPEAT           ; forward to K-REPEAT if so

;   having excluded a repeating key we can now consider a new key.
;   the second set is always examined before the first.

        bit 7,(hl)              ; is the key map free ?
        jr nz,K_NEW             ; forward to K-NEW if so.

        ex de,hl                ; bring back KSTATE-0
        bit 7,(hl)              ; is it free ?
        ret z                   ; return if not.
                                ; as we have a key but nowhere to put it yet.

;   continue or jump to here if one of the buffers was free.

;; K-NEW
K_NEW:
        ld e,a                  ; store key in E
        ld (hl),a               ; place in free location
        inc hl                  ; advance to the interrupt counter
        ld (hl),0x05            ; and initialize counter to 5
        inc hl                  ; advance to the delay
        ld a,(0x5C09)           ; pick up the system variable REPDEL
        ld (hl),a               ; and insert that for first repeat delay.
        inc hl                  ; advance to last location of state map.

        ld c,(iy+0x07)          ; pick up MODE  (3 bytes)
        ld d,(iy+0x01)          ; pick up FLAGS (3 bytes)
        push hl                 ; save state map location
                                ; Note. could now have used, to avoid IY,
                                ; ld l,$41; ld c,(hl); ld l,$3B; ld d,(hl).
                                ; six and two threes of course.

        call K_DECODE           ; routine K-DECODE

        pop hl                  ; restore map pointer
        ld (hl),a               ; put the decoded key in last location of map.

;; K-END
K_END:
        ld (0x5C08),a           ; update LASTK system variable.
        set 5,(iy+0x01)         ; update FLAGS  - signal a new key.
        ret                     ; return to interrupt routine.

; -----------------------
; THE 'REPEAT KEY' BRANCH
; -----------------------
;   A possible repeat has been identified. HL addresses the raw key.
;   The last location of the key map holds the decoded key from the first 
;   context.  This could be a keyword and, with the exception of NOT a repeat 
;   is syntactically incorrect and not really desirable.

;; K-REPEAT
K_REPEAT:
        inc hl                  ; increment the map pointer to second location.
        ld (hl),0x05            ; maintain interrupt counter at 5.
        inc hl                  ; now point to third location.
        dec (hl)                ; decrease the REPDEL value which is used to
                                ; time the delay of a repeat key.

        ret nz                  ; return if not yet zero.

        ld a,(0x5C0A)           ; fetch the system variable value REPPER.
        ld (hl),a               ; for subsequent repeats REPPER will be used.

        inc hl                  ; advance
        ld a,(hl)               ; pick up the key decoded possibly in another
                                ; context.
                                ; Note. should compare with $A5 (RND) and make
                                ; a simple return if this is a keyword.
                                ; e.g. cp $a5; ret nc; (3 extra bytes)
        jr K_END                ; back to K-END

; ----------------------
; THE 'KEY-TEST' ROUTINE
; ----------------------
;   also called from s-inkey$
;   begin by testing for a shift with no other.

;; K-TEST
K_TEST:
        ld b,d                  ; load most significant key to B
                                ; will be $FF if not shift.
        ld d,0x00               ; and reset D to index into main table
        ld a,e                  ; load least significant key from E
        cp 0x27                 ; is it higher than 39d   i.e. FF
        ret nc                  ; return with just a shift (in B now)

        cp 0x18                 ; is it symbol shift ?
        jr nz,K_MAIN            ; forward to K-MAIN if not

;   but we could have just symbol shift and no other

        bit 7,b                 ; is other key $FF (ie not shift)
        ret nz                  ; return with solitary symbol shift


;; K-MAIN
K_MAIN:
        ld hl,MAIN_KEYS         ; address: MAIN-KEYS
        add hl,de               ; add offset 0-38
        ld a,(hl)               ; pick up main key value
        scf                     ; set carry flag
        ret                     ; return    (B has other key still)

; ----------------------------------
; THE 'KEYBOARD DECODING' SUBROUTINE
; ----------------------------------
;   also called from s-inkey$

;; K-DECODE
K_DECODE:
        ld a,e                  ; pick up the stored main key
        cp 0x3A                 ; an arbitrary point between digits and letters
        jr c,K_DIGIT            ; forward to K-DIGIT with digits, space, enter.

        dec c                   ; decrease MODE ( 0='KLC', 1='E', 2='G')

        jp m,K_KLC_LET          ; to K-KLC-LET if was zero

        jr z,K_E_LET            ; to K-E-LET if was 1 for extended letters.

;   proceed with graphic codes.
;   Note. should selectively drop return address if code > 'U' ($55).
;   i.e. abort the KEYBOARD call.
;   e.g. cp 'V'; jr c,addit; pop af ;pop af ;;addit etc. (6 extra bytes).
;   (s-inkey$ never gets into graphics mode.)

t/data/zx48_base.asm  view on Meta::CPAN


;; K-GRA-DGT
K_GRA_DGT:
        ld hl,CTL_CODES-0x30    ; $0230 base address of CTL-CODES

        cp 0x39                 ; is key '9' ?
        jr z,K_LOOK_UP          ; back to K-LOOK-UP - changed to $0F, GRAPHICS.

        cp 0x30                 ; is key '0' ?
        jr z,K_LOOK_UP          ; back to K-LOOK-UP - changed to $0C, delete.

;   for keys '0' - '7' we assign a mosaic character depending on shift.

        and 0x07                ; convert character to number. 0 - 7.
        add a,0x80              ; add offset - they start at $80

        inc b                   ; destructively test for shift
        ret z                   ; and return if not pressed.

        xor 0x0F                ; toggle bits becomes range $88-$8F
        ret                     ; return.

; ---

;   now digits in 'KLC' mode

;; K-KLC-DGT
K_KLC_DGT:
        inc b                   ; return with digit codes if neither
        ret z                   ; shift key pressed.

        bit 5,b                 ; test for caps shift.

        ld hl,CTL_CODES-0x30    ; prepare base of table CTL-CODES.
        jr nz,K_LOOK_UP         ; back to K-LOOK-UP if shift pressed.

;   must have been symbol shift

        sub 0x10                ; for ASCII most will now be correct
                                ; on a standard typewriter.

        cp 0x22                 ; but '@' is not - see below.
        jr z,K___CHAR           ; forward to K-@-CHAR if so

        cp 0x20                 ; '_' is the other one that fails
        ret nz                  ; return if not.

        ld a,0x5F               ; substitute ASCII '_'
        ret                     ; return.

; ---

;; K-@-CHAR
K___CHAR:
        ld a,0x40               ; substitute ASCII '@'
        ret                     ; return.


; ------------------------------------------------------------------------
;   The Spectrum Input character keys. One or two are abbreviated.
;   From $00 Flash 0 to $FF COPY. The routine above has decoded all these.

;  | 00 Fl0| 01 Fl1| 02 Br0| 03 Br1| 04 In0| 05 In1| 06 CAP| 07 EDT|
;  | 08 LFT| 09 RIG| 0A DWN| 0B UP | 0C DEL| 0D ENT| 0E SYM| 0F GRA|
;  | 10 Ik0| 11 Ik1| 12 Ik2| 13 Ik3| 14 Ik4| 15 Ik5| 16 Ik6| 17 Ik7|
;  | 18 Pa0| 19 Pa1| 1A Pa2| 1B Pa3| 1C Pa4| 1D Pa5| 1E Pa6| 1F Pa7|
;  | 20 SP | 21  ! | 22  " | 23  # | 24  $ | 25  % | 26  & | 27  ' |
;  | 28  ( | 29  ) | 2A  * | 2B  + | 2C  , | 2D  - | 2E  . | 2F  / |
;  | 30  0 | 31  1 | 32  2 | 33  3 | 34  4 | 35  5 | 36  6 | 37  7 |
;  | 38  8 | 39  9 | 3A  : | 3B  ; | 3C  < | 3D  = | 3E  > | 3F  ? |
;  | 40  @ | 41  A | 42  B | 43  C | 44  D | 45  E | 46  F | 47  G |
;  | 48  H | 49  I | 4A  J | 4B  K | 4C  L | 4D  M | 4E  N | 4F  O |
;  | 50  P | 51  Q | 52  R | 53  S | 54  T | 55  U | 56  V | 57  W |
;  | 58  X | 59  Y | 5A  Z | 5B  [ | 5C  \ | 5D  ] | 5E  ^ | 5F  _ |
;  | 60  £ | 61  a | 62  b | 63  c | 64  d | 65  e | 66  f | 67  g |
;  | 68  h | 69  i | 6A  j | 6B  k | 6C  l | 6D  m | 6E  n | 6F  o |
;  | 70  p | 71  q | 72  r | 73  s | 74  t | 75  u | 76  v | 77  w |
;  | 78  x | 79  y | 7A  z | 7B  { | 7C  | | 7D  } | 7E  ~ | 7F  © |
;  | 80 128| 81 129| 82 130| 83 131| 84 132| 85 133| 86 134| 87 135|
;  | 88 136| 89 137| 8A 138| 8B 139| 8C 140| 8D 141| 8E 142| 8F 143|
;  | 90 [A]| 91 [B]| 92 [C]| 93 [D]| 94 [E]| 95 [F]| 96 [G]| 97 [H]|
;  | 98 [I]| 99 [J]| 9A [K]| 9B [L]| 9C [M]| 9D [N]| 9E [O]| 9F [P]|
;  | A0 [Q]| A1 [R]| A2 [S]| A3 [T]| A4 [U]| A5 RND| A6 IK$| A7 PI |
;  | A8 FN | A9 PNT| AA SC$| AB ATT| AC AT | AD TAB| AE VL$| AF COD|
;  | B0 VAL| B1 LEN| B2 SIN| B3 COS| B4 TAN| B5 ASN| B6 ACS| B7 ATN|
;  | B8 LN | B9 EXP| BA INT| BB SQR| BC SGN| BD ABS| BE PEK| BF IN |
;  | C0 USR| C1 ST$| C2 CH$| C3 NOT| C4 BIN| C5 OR | C6 AND| C7 <= |
;  | C8 >= | C9 <> | CA LIN| CB THN| CC TO | CD STP| CE DEF| CF CAT|
;  | D0 FMT| D1 MOV| D2 ERS| D3 OPN| D4 CLO| D5 MRG| D6 VFY| D7 BEP|
;  | D8 CIR| D9 INK| DA PAP| DB FLA| DC BRI| DD INV| DE OVR| DF OUT|
;  | E0 LPR| E1 LLI| E2 STP| E3 REA| E4 DAT| E5 RES| E6 NEW| E7 BDR|
;  | E8 CON| E9 DIM| EA REM| EB FOR| EC GTO| ED GSB| EE INP| EF LOA|
;  | F0 LIS| F1 LET| F2 PAU| F3 NXT| F4 POK| F5 PRI| F6 PLO| F7 RUN|
;  | F8 SAV| F9 RAN| FA IF | FB CLS| FC DRW| FD CLR| FE RET| FF CPY|

;   Note that for simplicity, Sinclair have located all the control codes
;   below the space character.
;   ASCII DEL, $7F, has been made a copyright symbol.
;   Also $60, '`', not used in BASIC but used in other languages, has been
;   allocated the local currency symbol for the relevant country -
;    £  in most Spectrums.

; ------------------------------------------------------------------------


;**********************************
;** Part 3. LOUDSPEAKER ROUTINES **
;**********************************

; Documented by Alvin Albrecht.

; ------------------------------
; Routine to control loudspeaker
; ------------------------------
; Outputs a square wave of given duration and frequency
; to the loudspeaker.
;   Enter with: DE = #cycles - 1
;               HL = tone period as described next
;
; The tone period is measured in T states and consists of
; three parts: a coarse part (H register), a medium part



( run in 0.600 second using v1.01-cache-2.11-cpan-39bf76dae61 )