;;Checks, which interrupts are allowed 
        ORG     100H        ;Tell the assembler to start at address 0x100
        CALL    CLS         ;Clear screen
        LD      HL,BANNER   ;Load the banner text
        LD      B,0CH       ;Set the length of the banner text
        LD      DE,0H       ;Start output in the top left corner
        CALL    84CDH       ;Call str_out
        IN      A,(17H)     ;Read the interrupt sources
        LD      HL,BUF      ;Load the buffer address
        CALL    BTOHEX      ;Convert the register A to hexstr.
        LD      B,02H       ;Set the output length to 2
        LD      DE,0DH      ;Place the output cursor to row 0, col 13
        CALL    84CDH       ;Call str_out
        LD      HL,IREG     ;Load the banner line
        LD      B,0CH       ;Load the length of the banner text
        LD      DE,100H     ;Start output at the second row
        CALL    84CDH       ;Call str_out
        LD      A,I         ;Load the value of I into A
        LD      HL,BUF      ;Use the buffer
        CALL    BTOHEX      ;Convert the register A to hexstr
        LD      B,02H       ;Set the length to 2
        LD      DE,10DH     ;Place the cursor to row 1, col 13
        CALL    84CDH       ;Call str_out        
        RET                 ;Return from program call
;;Clear the screen 
CLS:    LD      A,20H       ;Use a space as output
        LD      B,60H       ;Repeat for entire screen (96 places)
        LD      DE,0H       ;Start in top left corner
        CALL    0BFEEH      ;Call the str_repeat function
        RET
;;Convert the contents of A into a hex-string and stores the result in the buffer pointed in HL
BTOHEX: PUSH    AF          ;Store A onto the stack for later use
        LD      B,4         ;Init a loop for shifting the register
LP1:    SRL     A           ;Shift the MSN down to the least significant Nibble
        DJNZ    LP1         ;Shift again, until all 4 bits where shifted.
        CALL    HEXDGT      ;Converts the LSN to hex
        INC     HL          ;Point HL to the next byte in buffer
        POP     AF          ;Retrieve the original A
        AND     0FH         ;Cut the first digit of the hex no.
        CALL    HEXDGT      ;Call HEXDIGIT again for the second digit.
        LD      HL,BUF      ;Restore the buffer address
        RET
;;Converts the least significant nibble in A into a ASCII hex-digit and stores the result
HEXDGT: CP      0AH         ;Check if the number is smaller than 10
        JR      C,SKIP      ;Skip the next instruction, if it is
        ADD     A,07H       ;If the value is >10, we need to skip the chars between '9' and 'A'
SKIP:   ADD     A,30H       ;Converts the number into its ASCII digit
        LD      (HL),A      ;Store the digit in the correct location.
        RET
BANNER: DB      'Interrupts: '
IREG:   DB      'I-Register: '
BUF:    DS      2           ;Define a 2 byte buffer.
        END                 ;End assembly
