Skip to content

hla.inc

IanM-Matrix1 edited this page Aug 29, 2020 · 1 revision

Table of Contents

The code in this file both provides the simple conditional if...else...endif and a flexible for of looping bases upon the processor flags.

Structures current available

if ... [else] ... endif

What it does

The 'if' will insert a relative branch instruction based on your chosen condition, branching to the 'else' if it's present, or to the 'endif' otherwise.

The 'else' part of the structure is optional, but if present will insert a JMP instruction to the 'endif'.

The 'endif' must be present.

Statements

The opening 'if' statement can be one of the following:

  • if_eq
  • if_zero
  • if_ne
  • if_not_zero
  • if_plus
  • if_minus
  • if_c_set
  • if_c_clr
  • if_v_set
  • if_v_clr
Kickass does not provide arithmetic comparison branches, so an extension was included to do so. This is activated by defining HLA_ARITH_COMPARE, which will activate the following 4 forms of the if statement:
  • if_lt - if less than
  • if_gt - if greater than
  • if_le - if less than or equal
  • if_ge - if greater than or equal
Where lt is less than, gt is greater than, le is less than or equal, and ge is greater than or equal.

do ... [exit_loop|while] ... loop

What it does

The opening 'do' statement must be present.

Within the structure, then can be one or more of the 'exit_loop' or 'while' instructions.

The 'exit_loop' is an unconditional statement and will cause the loop to terminate immediately when reached.

The 'while' statement will cause the loop to terminate immediately if the condition it is checking is false.

The 'loop' statement signals the end of the loop structure. If a loop with a condition is used, the statement will loop back to the start of the loop structure if the configution it is checking is true. If a loop without a condition is used, it will JMP to the top of the loop structure.

Statements

  • while_eq
  • while_zero
  • while_ne
  • while_not_zero
  • while_plus
  • while_minus
  • while_c_set
  • while_c_clr
  • while_v_set
  • while_v_clr
If you define HLA_ARITH_COMPARE, the following 4 statements are included:
  • while_lt - while less than
  • while_gt - while greater than
  • while_le - while less than or equal
  • while_ge - while greater than or equal
The 'loop' statement marks the end of the loop and can be one of the following:
  • loop
  • loop_if_eq
  • loop_if_zero
  • loop_if_ne
  • loop_if_not_zero
  • loop_if_plus
  • loop_if_minus
  • loop_if_c_set
  • loop_if_c_clr
  • loop_if_v_set
  • loop_if_v_clr
If you define HLA_ARITH_COMPARE, the following 4 statements are included:
  • loop_if_lt - loop if less than
  • loop_if_gt - loop if greater than
  • loop_if_le - loop if less than or equal
  • loop_if_ge - loop if greater than or equal

Examples

Simple 'if'

    ...
    <operation that sets the zero flag>
    if_eq
        jsr do_something
    endif
    ...

Infinite loop

    ...
    do
        jsr update_game
    loop

A simple conditional loop

On the C64, this code will loop until raster line 255 ($ff) is reached. Note that although the code itself is less compact than the equivalent plain assembly, the structure makes the code a little more readable.

    ...
    lda #$ff
    do
        cmp $d012
    loop_if_ne
    ...

New pseudo-opcodes included

When HLA_ARITH_COMPARE is defined, the following 4 new branch opscodes are also included:

  • blt - branch if less than
  • bgt - branch if greater than
  • ble - branch if less than or equal
  • bge - branch if greater than or equal
The bgt and ble opcodes are 4 bytes in size rather than the usual 2 bytes of a branch because they consist of 2 branch instructions internally.

User expansion

Two additional macros have been exported to allow expansion of the 'if' tests and 'loop' tests:

  • add_patch_point(jump, type, subtype)
  • terminate_loop(jump)
All of the existing commands use these macros, and although these commands are pseudocommands, it is valid to also use macros if you want to use parameters.

Examples of both macros in use can be found in the 'hla_controller.inc' include file.

add_patch_point

This allows you to insert a branch or JMP statement at the current point in the code. The branch of JMP will be patched by the matching 'endif' or 'loop' statement.

When building an 'if' statement, you should specify a type of "if", and a subtype of "if". If you wish to also include a secondary test, then the type remains "if", but the subtype should be set to "test".

When building a 'while' statement, you should specify a type of "loop" and a subtype of "test". As there are no restrictions on the number of 'while' statements inside a loop, there are no other options.

terminate_loop

This allows you to build a new 'loop' type statement that uses the branch or JMP statement you specifiy to return to the top of the loop. It may only be used once for the loop and must be at the end.

Clone this wiki locally